Close

C++ STL Algorithms – Sort- Part-1

Sorting is one of the most widely used algorithmic primitive in programming.  C++ Standard Template Library (STL) provides an efficient implementation of the sort algorithm. It is always better to use this algorithm instead of writing our own implementation because of the following benefits. It’s performance would surely be better than your own implementation. It’s…

Size of an empty object in C++

What is the size of an empty object in C++? This is one of the most frequently asked questions on forums. For example consider the following code snippet. class A { }; A aOb; cout << sizeof(aOb); The size of an empty object is not zero to ensure that the addresses of two different objects…

Check if two binary trees are identical

Given two binary tress, how do we check if they are identical in structure, and  contents? For example the following two binary trees are identical. We can solve this problem using recursion effectively. The function checks if the root element is equal and use the same function to check if it’s left and right sub-trees…