Browsing the topic Trees
Question: Given a binary tree, find out if the tree can be folded or not.
A tree can be folded if left and right subtrees of the tree are structure wise mirror image of each other. An empty tree is considered as foldable.
Given a binary tree, write a function to get the maximum width of the given tree. Width of a tree is maximum of widths of all levels.
Read More »Write a program that converts a given tree to its Double tree. To create Double tree of the given tree, create a new duplicate for each node, and insert the duplicate as the left child of the original node.
Read More »For the below example tree, all root-to-leaf paths are:
Read More »Let us consider the below traversals:
Inorder sequence: D B E A F C
Preorder sequence: A B D E C F
Given a binary tree and a number, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals the given number.
Read More »Using Morris Traversal, we can traverse the tree without using stack and recursion. The idea of Morris Traversal is based on Threaded Binary Tree.
Read More »Using Stack is the obvious way to traverse tree without recursion. Below is an algorithm for traversing binary tree using stack. See this for step wise step execution of the algorithm.
Read More »A tree where no leaf is much farther away from the root than any other leaf. Different balancing schemes allow different definitions of “much farther” and different amounts of work to keep them balanced.
Read More »The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree.
Read More »Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
6 Comments | Filed under TreesAsked by Shekhar
Question: Given an arbitrary binary tree, convert it to a binary tree that holds Children Sum Property. You can only increment data values in any node.
Asked by Shekhar
Given a binary tree, write a function that returns true if the tree satisfies below property.
Write a function to print spiral order traversal of a tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7.
Read More »A binary search tree (BST) is a node based binary tree data structure which has the following properties.
Read More »A node is a leaf node if both left and right child nodes of it are NULL.
Here is an algorithm to get the leaf node count.
Level order traversal of a tree is breadth first traversal for the tree.
Read More »This is quite simple. Just traverse the node from root to left recursively until left is NULL. The node whose left is NULL is the node with minimum value.
Read More »Asked by Varun Bhatia.
Question:
Write a recursive function treeToList(Node root) that takes an ordered binary tree and rearranges the internal pointers to make a circular doubly linked list out of the tree nodes.
Asked by Varun Bhatia
Given the values of two nodes in a *binary search tree*, write a c program to find the lowest common ancestor. You may assume that both values already exist in the tree.
Asked by Varun Bhatia
Here is the solution.

