Saturday, October 18, 2014

Given a node in binary tree - Check if left and right subtree are mirror of each other

Problem A binary tree is a mirror image of itself if its left and right subtrees are identical mirror images i.e., the binary tree is symmetrical. This is best explained with a few examples. Example 1 / \ 2 2 TRUE 1 / \ 2 2 \ 3 FALSE 1 / \ 2 2 / \ / \ 4 3 3 4 TRUE 1 / \ 2 2 / \ / \ 3 4 3 4 FALSE 1 / \ 2 2 / \ 3 3 TRUE Solution Method 1 - Recursiion mirrorEquals(BTree left , BTree right) Basically compare the left subtree...

Friday, October 17, 2014

Queue ADT

Definition :- A queue is a collection of same type of entities, which ensures that all entities in collection will have a sequential storage structure that permits access only at the two ends of the sequence.  We refer to the ends of the sequence as the front and rear.  The first element in queue have the position as front and value or pointer or front changes according to the solution of the given problem. Rear is the terminal position...