# Category Archives: Trees

## Lowest Common Ancestor in a Binary Search Tree.August 9, 2009

Given values of two nodes in a Binary Search Tree, write a c program to find the Lowest Common Ancestor (LCA). You may assume that both the values exist in the tree.

## Given a binary tree, print out all of its root-to-leaf paths one per line.

Asked by Varun Bhatia Here is the solution.

## If you are given two traversal sequences, can you construct the binary tree?August 2, 2009

It depends on what traversals are given. If one of the traversal methods is Inorder then the tree can be constructed, otherwise not.

## Write an Efficient Function to Convert a Binary Tree into its Mirror TreeJune 27, 2009

Mirror of a Tree: Mirror of a Binary Tree T is another Binary Tree M(T) with left and right children of all non-leaf nodes interchanged.

## Write a program to Delete a Tree.

To delete a tree we must traverse all the nodes of the tree and delete them one by one. So which traversal we should use – Inorder or Preorder or Postorder. Answer is simple – Postorder, because before deleting the parent node we should delete its children nodes first We can delete tree with other… Read More »

## Write a Program to Find the Maximum Depth or Height of a Tree

Given a binary tree, find height of it. Height of empty tree is 0 and height of below tree is 3.

## Write Code to Determine if Two Trees are IdenticalJune 26, 2009

Two trees are identical when they have same data and arrangement of data is also same.

## Write a program to Calculate Size of a treeJune 23, 2009

Size of a tree is the number of elements present in the tree. Size of the below tree is 5.

## Tree Traversals (Inorder, Preorder and Postorder)

Unlike linear data structures (Array, Linked List, Queues, Stacks, etc) which have only one logical way to traverse them, trees can be traversed in different ways. Following are the generally used ways for traversing trees.