# Category Archives: Trees

## Averages of Levels in Binary TreeJuly 14, 2017

Given a non-empty binary tree, print the average value of the nodes on each level. Examples: Input : 4 / \ 2 9 / \… Read More »

## Maximum sum from a tree with adjacent levels not allowedJuly 13, 2017

Given a binary tree with positive integer values. Find the maximum sum of nodes such that we cannot pick two levels for computing sum Examples:… Read More »

## Query for ancestor-descendant relationship in a treeJuly 10, 2017

Given a rooted tree with N vertices and N-1 edges. We will be given many pairs of vertices u and v, we need to tell… Read More »

## Shortest path between two nodes in array like representation of binary tree

Consider a binary tree in which each node has two children except the leaf nodes. If a node is labeled as ‘v’ then its right… Read More »

## Replace each node in binary tree with the sum of its inorder predecessor and successorJuly 7, 2017

Given a binary tree containing n nodes. The problem is to replace each node in the binary tree with the sum of its inorder predecessor… Read More »

## Print common nodes on path from root (or common ancestors)July 4, 2017

Given a binary tree and two nodes, the task is to Print all the nodes that are common for 2 given nodes in a binary… Read More »

## Merge Two Binary Trees by doing Node Sum (Recursive and Iterative)June 22, 2017

Given two binary trees. We need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum… Read More »

## Print the path common to the two paths from the root to the two given nodesJune 19, 2017

Given a binary tree with distinct nodes(no two nodes have the same have data values). The problem is to print the path common to the… Read More »

## Find mirror of a given node in Binary treeJune 18, 2017

Given a Binary tree, the problem is to find mirror of a given node. The mirror of a node is a node which exist at… Read More »

## Print path from root to a given node in a binary tree

Given a binary tree with distinct nodes(no two nodes have the same have data values). The problem is to print the path from root to… Read More »

## Count Balanced Binary Trees of Height hJune 17, 2017

Given a height h, count and return the maximum number of balanced binary trees possible with height h. A balanced binary tree is one in… Read More »

## Splay Tree | Set 3 (Delete)June 13, 2017

It is recommended to refer following post as prerequisite of this post. Splay Tree | Set 1 (Search) Following are the different cases to delete… Read More »

## Iterative method to check if two trees are mirror of each otherJune 12, 2017

Given two binary tress. The problem is to check whether the two binary tress are mirrors of each other or not. Mirror of a Binary… Read More »