# Category Archives: Trees

## Node having maximum sum of immediate children and itself in n-ary treeOctober 11, 2017

Given an N-Ary tree, find and return the node for which sum of data of all children and the node itself is maximum. In the… Read More »

## Sub-tree with minimum color difference in a 2-coloured treeOctober 9, 2017

A tree with N nodes and N-1 edges is given with 2 different colours for its nodes. Find the sub-tree with minimum colour difference i.e.… Read More »

## Kth ancestor of a node in binary tree | Set 2October 6, 2017

Given a binary tree in which nodes are numbered from 1 to n. Given a node and a positive integer K. We have to print… Read More »

## Inorder Successor of a node in Binary TreeOctober 4, 2017

Given a binary tree and a node, we need to write a program to find inorder successor of this node. Inorder Successor of a node… Read More »

## Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror treeOctober 3, 2017

Given two arrays that represent Preorder traversals of a full binary tree and its mirror tree, we need to write a program to construct the… Read More »

## Given a n-ary tree, count number of nodes which have more number of children than parentsOctober 2, 2017

Given a N-ary tree represented as adjacency list, we need to write a program to count all such nodes in this tree which has more… Read More »

## Check if given Preorder, Inorder and Postorder traversals are of same treeOctober 1, 2017

Given Preorder , Inorder and Postorder traversals of some tree. Write a program to check if they all are of the same tree. Examples: Input… Read More »

## Right view of Binary Tree using Queue

Given a Binary Tree, print Right view of it. Right view of a Binary Tree is set of nodes visible when tree is visited from… Read More »

## Pairwise Swap leaf nodes in a binary tree

Given a binary tree, we need to write a program to swap leaf nodes in the given binary tree pairwise starting from from left to… Read More »

## Print all leaf nodes of a Binary Tree from left to rightSeptember 30, 2017

Given a binary tree, we need to write a program to print all leaf nodes of the given binary tree from left to right. That… Read More »

## Sum of nodes on the longest path from root to leaf nodeSeptember 28, 2017

Given a binary tree containing n nodes. The problem is to find the sum of all nodes on the longest path from root to leaf… Read More »

## K-th ancestor of a node in Binary TreeSeptember 27, 2017

Given a binary tree in which nodes are numbered from 1 to n. Given a node and a positive integer K. We have to print… Read More »

## General Tree (Each node can have arbitrary number of children) Level Order TraversalSeptember 26, 2017

Given a generic tree, perform a Level order traversal and print all of its nodes Input : 10 / / \ \ 2 34 56… Read More »

## Sum of all the parent nodes having child node xSeptember 25, 2017

Given a binary tree containing n nodes. The problem is to find the sum of all the parent node’s which have a child node with… Read More »

## DFS for a n-ary tree (acyclic graph) represented as adjacency listSeptember 22, 2017

A tree consisting of n nodes is given, we need to print its DFS. Examples : Input : Edges of graph 1 2 1 3… Read More »