## Print two-dimensional view of a binary tree

Given a binary tree, write an efficient algorithm to print two-dimensional view of a binary tree.

## Construct a Binary Tree from Ancestor Matrix

Given an ancestor matrix, whose cell (i, j) has value true if i is ancestor of j in a binary tree, construct a binary tree from it where binary tree nodes are labelled from 0 to n-1 where n is the size of the ancestor matrix.

## Calculate height of a binary tree with leaf nodes forming a circular doubly linked list

Write an algorithm to compute the height of a binary tree with leaf nodes forming a circular doubly linked list where the left and right pointers of the leaf node will act as a previous and next pointer of circular doubly linked list respectively.   For example, consider below binary tree. The leaf nodes are …

## Huffman Coding Compression Algorithm

Huffman Coding (also known as Huffman Encoding) is a algorithm for doing data compression and it forms the basic idea behind file compression. This post talks about fixed length and variable length encoding, uniquely decodable codes, prefix rules and construction of Huffman Tree.

## Check if given Binary Tree is Height Balanced or not

Given a binary tree, write an efficient algorithm to check if tree is height balanced or not. In a height balanced tree, the absolute difference between height of left subtree and right subtree for every node is 0 or 1.

## Treap Data Structure

A Treap Data Structure is basically a combination of a binary search tree and a heap.   Binary Search Trees – Deletions and additions of nodes can make the tree unbalanced (heavier on sides, therefore, the property we value about BSTs, the ability to distribute data by equal divisions, goes out of whack). Therefore we …

## Print Binary Tree Structure with its contents in C++

Given a binary tree, write an efficient algorithm to print binary tree structure in standard output.

## Find the Diagonal Sum of given Binary Tree

Given a binary tree, calculate sum of all nodes for each diagonal having negative slope (\). Assume that the left and right child of a node makes 45 degree angle with the parent.

## Determine if given Binary Tree is a BST or not

Given a Binary Tree, determine if it is a BST or not.   This problem has a simple recursive solution. The BST property “every node on the right subtree has to be larger than the current node and every node on the left subtree has to be smaller than the current node” is the key …

## Find maximum sum root to leaf path in a binary tree

Given a binary tree, write an efficient algorithm to find maximum sum root to leaf path i.e. maximum sum path from root node to any leaf node in it.

## Truncate binary tree to remove nodes which lie on a path having sum less than K

Given a binary tree, a complete path is defined as a path from root to a leaf. The sum of all nodes on that path is defined as the sum of that path. Given a number K, remove nodes from the tree which lie on a path having sum less than K.

## Convert given binary tree to full tree by removing half nodes

Given a binary tree, convert it to full tree by removing half nodes (remove nodes having one children).