Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Search a 2D Matrix in C++
Suppose we have write an efficient algorithm to searches for a value in one m x n matrix. This matrix has some properties like below −Each row is sorted from left to rightThe first number of each row is greater than the last integer of the previous row.So if the matrix is like −1357101116202330345053627898And if the target value is 16, then the output will be True.Let us see the steps −n := number of rows, if n is 0, then return false, m := number of columns, if m = 0, then return falselow := 0 and high := n ...
Read MoreContainership in C++
In this tutorial, we will be discussing a program to understand containership in C++.The parameter if a certain class contains another class is called as containership. The inside class is called contained class, while the class in which it is present is called container class.Example#include using namespace std; class first { public: first(){ cout
Read MoreMerge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), inplace_merge
In this tutorial, we will be discussing a program to understand the various merge operations using STL in C++.The merge() function is used to merge two sorted containers in a way that the new container is also sorted. Further includes() is used to check if the elements from first container are present in the second one.Example#include #include #include using namespace std; int main(){ vector v1 = {1, 3, 4, 5, 20, 30}; vector v2 = {1, 5, 6, 7, 25, 30}; //initializing resultant vector vector v3(12); merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin()); cout
Read MoreOperator overloading in C++ to print contents of vector, map, pair ..
In this tutorial, we will be discussing a program to understand operator overloading in C++ to print contents of vector, map and pair.Operator overloading is the function of operators which gives them the ability to act on User defined objects and work accordingly in a similar fashion.ExampleVector#include #include using namespace std; template ostream& operator
Read Moretransform_inclusive_scan() function in C++
In this tutorial, we will be discussing a program to understand the transform_inclusive_scan() function in C++.Example#include #include using namespace std; namespace point_input_iterator { template OutputItrator transform_inclusive_scan(InputItrator first, InputItrator last, OutputItrator d_first, BinaryOperation binary_op, UnaryOperation unary_op){ *d_first = unary_op(*first); first++; d_first++; for (auto it = first; it != last; it++) { //calculating the prefix sum *d_first = binary_op(unary_op(*it), *(d_first - ...
Read MoreOrder of Constructor/ Destructor Call in C++
In this tutorial, we will be discussing a program to understand the order of constructor/ destructor in C++.Order of constructor/destructor refers to the pattern in which the constructors of various classes are called during inheritance of classes.Example#include using namespace std; //parent class class Parent{ public: Parent(){ cout
Read MoreRemove Duplicates from Sorted Array II in C++
Suppose we have a sorted array nums, we have to remove the duplicates in-place such that duplicates elements will appear at most twice and return the new length. To do this task we cannot take extra space. We have to solve this with O(1) amount of space. For example, if the array is like [0,0,0,1,1,1,1,2,3,3], then the output will be [0,0,1,1,2,3,3], its length is 7Let us see the steps −len := 2 and n := size of arrayif n
Read MoreOrdered Set and GNU C++ PBDS
In this tutorial, we will be discussing a program to understand ordered set and GNU C++ PBDS.Ordered set is a policy based structure other than those in the STL library. The ordered set keeps all the elements in a sorted order and doesn’t allow duplicate values.Example#include using namespace std; #include #include using namespace __gnu_pbds; #define ordered_set tree int main(){ //declaring ordered set ordered_set o_set; o_set.insert(5); o_set.insert(1); o_set.insert(2); cout
Read MorePrint Kth least significant bit of a number in C++
In this problem, we are given two numbers n and k. Our task is to print the kth least significant bit of the number n.Let’s take an example to understand the problemInput: n = 12 , k = 3 Output 1 Explanation: Let’s see the binary representation of n: 12 = 1100Now, 3rd least significant bit is 1.To solve this problem we will use the binary bits of the number. And yield the kth bit of the number. For this, we will use binary shifting of the number and left-shift the number (k-1) times. Now on doing end operation of ...
Read MoreUsing class to implement Vector Quantities in C++
In this tutorial, we will be discussing a program to understand how to use class to implement vector quantities in C++.Vector quantities are the ones which have both magnitude and direction. Here we will be implementing them using classes and then performing basic operations on them.Example#include #include using namespace std; class Vector { private: int x, y, z; //components of the Vector public: Vector(int x, int y, int z){ this->x = x; this->y = y; this->z = z; } Vector operator+(Vector v); ...
Read More