# Category Archives: Trees

## Connect Nodes at same Level (Level Order Traversal)August 16, 2017

Write a function to connect all the adjacent nodes at the same level in a binary tree. Example: Input Tree A / \ B C… Read More »

## Print Levels of all nodes in a Binary TreeAugust 15, 2017

Given a Binary Tree and a key, write a function that prints levels of all keys in given binary tree. For example, consider the following… Read More »

## Find All Duplicate SubtreesAugust 14, 2017

Given a binary tree, find all duplicate subtrees. For each duplicate subtrees, we only need to return the root node of any one of them.… Read More »

## Number of turns to reach from one node to other in binary treeAugust 11, 2017

Given a binary tree and two nodes. The task is to count the number of turns needs to reach from one node to another node… Read More »

## Calculate number of nodes in all subtrees | Using DFSAugust 10, 2017

Given a tree in form of adjacency list we have to calculate the number of nodes in the subtree of each node, while calculating the… Read More »

## Leftist Tree / Leftist HeapAugust 2, 2017

A leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node has an s-value (or rank… Read More »

## Check mirror in n-ary treeJuly 27, 2017

Given two n-ary trees, the task is to check if they are mirror of each other or not. Print “Yes” if they are mirror of… Read More »

## Construct a complete binary tree from given array in level order fashionJuly 26, 2017

Given an array of elements, our task is to construct a complete binary tree from this array in level order fashion. That is, elements from… Read More »

## Print nodes at k distance from root | Iterative

Given a root of a tree, and an integer k. Print all the nodes which are at k distance from root. For example : Input… Read More »

## Get level of a node in binary tree | iterative approachJuly 25, 2017

Given a Binary Tree and a key, write a function that returns level of the key. For example, consider the following tree. If the input… Read More »

## Check if all levels of two trees are anagrams or notJuly 24, 2017

Given two binary trees, we have to check if each of their levels are anagrams of each other or not. Example: Tree 1: Level 0… Read More »

## Ternary Search Tree (Deletion)July 22, 2017

In the SET 1 post on TST we have described how to insert and search a node in TST. In this article we will discuss… Read More »

## Print middle level of perfect binary tree without finding heightJuly 17, 2017

Given a perfect binary tree, print nodes of middle level without computing its height. A perfect binary tree is a binary tree in which all… Read More »

## Factor Tree of a given Number

Factor Tree is an intuitive method to understand factors of a number. It shows how all the factors are been derived from the number. It… Read More »

## Iterative method to find ancestors of a given binary tree

Given a binary tree, print all the ancestors of a particular key existing in the tree without using recursion. Here we will be discussing the… Read More »