Sort in C++ standard template library

Two elements of complex data types are not directly comparable. Consider the student structure defined as below struct Student { int rollNo; char name[25]; char […]

Check if a Tree is Almost Complete Binary Tree

Given a pointer to the root node of the tree, write code to find if it is an Almost Complete Binary Tree or not? A […]

Separate Chaining: Hashing collision handling technique

It is almost impossible to design a generic hash system without collision. In case of collision, it need to be handled. There are multiple ways […]

Check if two node are siblings in a binary tree

Given a binary tree and two values. Find if these values appear in sibling nodes in the tree. For example, if tree is Then 2 […]

Check duplicate parenthesis in an expression

A valid mathematical expression can also have duplicate parenthesis as shown below: ((a+b)) (((a+(b)))+(c+d)) Write code to find if an expression has duplicate parenthesis. You […]

Next greater element

Print Next Greater Element for every element in the array. The Next greater Element of element x is first greater element on its right side. […]

Introducing Graph Data Structure with Adjacency matrix implementation

Binary tree is a specialization of Graph data structure. Node in a Graph is called a Vertex and the connection between two vertices is called […]

Recursive implementation of Insertion Sort

We discussed Insertion sort in detail earlier. This post shows the recursive implementation of Insertion Sort.

Count frequency of a number in a sorted array

Given a sorted array of numbers and a number x, count the number of occurrences of x in the array. Input: int arr[] = {1, […]

Counting Sort

It is used when there are few unique elements in an array. Counting sort takes O(n+k) time in the worst case, where n is number […]