Category Archives: Tree

Famous interview questions – binary tree algorithm

Find ceil value of input data in binary search tree in java (DFS/Example)

Given the binary search tree, we need to find the Ceil value of given input data.
What is Ceil value ? The smallest value just greater than or equal to given input data. We have already discussed about Floor of input data in BST. The logical flow of ceil value in BST is exactly same as that floor value. Let us find Ceil value for BST shown in Fig 1.

Connect nodes at same level (set next sibling)-binary tree DFS/example

Given a binary tree, we need to connect the nodes lying at same level. We have already discussed about the tree traversal using breadth first search algorithm, where we are printing the nodes level by level. By the end of this article we will achieve the same result using next sibling reference. In binary tree, we generally have following information.

Find K smallest element in binary search tree (BST) – DFS / example

Given a binary search tree (bst), we would like to find out K smallest element in BST. Traverse the binary search tree using depth first search (DFS) recursive algorithm. Perform InOrder binary tree traversal to find smallest K smallest element. InOrder tree traversal prints elements in sorted order. We can find out K smallest from sorted order… Read More »

Check given binary trees are Isomorphic in java (recursive / examples)

We are given two binary tree, we need to find out whether one binary tree is Isomorphic of other binary tree. What is Isomorphic meaning? As per English dictionary meaning is “being of identical or similar form, shape, or structure”. By apply above definition to our problem statement, If given binary have identical or similar form or shape or structure to another binary tree, we can say that trees are isomorphic.