Close

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…

Pair swapping in a linked list

Given a singly linked list, we have to swap the adjacent nodes in it. For example some input/output samples are given below Input                              output ————————————————- 1->2->3->4->X                      2->1->4->3->X 1->2->3->4->5->X      …

Merging k sorted lists

Given K sorted lists, how to merge them into a single sorted list? Let total number of elements in K sorted lists is N. We have to form a single sorted list of length N. For example let us consider the following input lists{4, 19, 27}{1, 6, 50, 73}{9, 45, 59, 67} The output should…