Merge K Sorted Arrays

Objective: Given k sorted array, write an algorithm to merge Them into One sorted array.

Example :

int [][] A = new int[5][];

A[0] = new int[] { 1, 5, 8, 9 };
A[1] = new int[] { 2, 3, 7, 10 };
A[2] = new int[] { 4, 6, 11, 15 };
A[3] = new int[] { 9, 14, 16, 19 };
A[4] = new int[] { 2, 4, 6, 9 };

Output:
[1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9, 9, 10, 11, 14, 15, 16, 19]

Read more

Populate Next Siblings Pointers in a Given Binary Tree OR Populate Next Right Pointers in Each Node

Objective: – Given a binary tree with three-pointers left, right, and nextSibling). Write the program to provide the nextsibling pointers.

This problem can also be referred as “Populating Next Right Pointers in Each Node

Example:

Provide the Next Siblings Pointers in a Given Binary Tree.
Provide the Next Siblings Pointers in a Given Binary Tree.

Approach:

Read more

Diameter Of a Binary Tree

Objective: – Given a binary tree, write an algorithm to find the diameter of the tree.

What is Diameter Of a Tree: Diameter of tree is defined as A longest path or route between any two nodes in a tree. The path may or may not for through the root.

Example:

Diameter Of a Binary Tree

Approach:

Read more