# Category Archives: Trees

## Find sum of all left leaves in a given Binary Tree

Given a Binary Tree, find sum of all left leaves in it. For example, sum of all left leaves in below Binary Tree is 5+1=6.

## Remove nodes on root to leaf paths of length < K

Given a Binary Tree and a number k, remove all nodes that lie only on root to leaf path(s) of length smaller than k.

## Find the closest leaf in a Binary Tree

Given a Binary Tree and a key ‘k’, find distance of the closest leaf from ‘k’.

## Diagonal Sum of a Binary Tree

Consider lines of slope -1 passing between nodes (dotted lines in below diagram). Diagonal sum in a binary tree is sum of all node’s data… Read More »

## Bottom View of a Binary Tree

Given a Binary Tree, we need to print the bottom view from left to right.

## Perfect Binary Tree Specific Level Order Traversal

Given a Perfect Binary Tree like below: (click on image to get a clear view)

## Print Nodes in Top View of Binary Tree

Top view of a binary tree is the set of nodes visible when the tree is viewed from the top. Given a binary tree, print… Read More »

## Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)

We have discussed Threaded Binary Tree. The idea of threaded binary trees is to make inorder traversal faster and do it without stack and without… Read More »

## Serialize and Deserialize an N-ary Tree

Given an N-ary tree where every node has at-most N children. How to serialize and deserialze it? Serialization is to store tree in a file… Read More »

## Serialize and Deserialize a Binary Tree

Serialization is to store tree in a file so that it can be later restored. The structure of tree must be maintained.

## Check if a given graph is tree or not

Write a function that returns true if a given undirected graph is tree and false otherwise. For example, the following graph is a tree.

## Print nodes between two given level numbers of a binary tree

Given a binary tree and two level numbers ‘low’ and ‘high’, print nodes from level low to level high.

## Find Height of Binary Tree represented by Parent array

A given array represents a tree in such a way that the array value gives the parent node of that particular index. The value of… Read More »

## Minimum no. of iterations to pass information to all nodes in the tree

Given a very large n-ary tree. Where the root node has some information which it wants to pass to all of its children down to… Read More »

## Convert left-right representation of a binary tree to down-right

Left-Right representation of a binary tree is standard representation where every node has a pointer to left child and another pointer to right child.