# Category: Recursion

## Merge Sort in a Linked list

Objective: Given a Linked List, Sort it using merge sort. Example: ->9->3->4->2->5->1 Sorted List: ->1->2->3->4->5->9 Approach: Reference : Merge Sort in array As it Merge sort, we apply the same logic , Divide and...

## AVL Tree – Insertion

What is AVL Tree : AVL tree is widely known as self-balancing binary search tree. It is named after its creator (Georgy Adelson-Velsky and Landis’ tree). In AVL Tree, the heights of child subtrees...

## Construct a binary tree from given Inorder and Level Order Traversal

Objective: – Given a inorder and level order traversal, construct a binary tree from that. Input: Inorder and level order traversal Approach: int[] inOrder = { 4, 2, 5, 1, 6, 3, 7 };...

## Construct Binary Search Tree from a given Preorder Traversal Using Stack (Without Recursion)

Objective: – Given a preorder traversal, construct BST from that, without using recursion. Input: Preorder traversal Similar Problem : This problem is similar to the Construct Binary Search Tree from a given Preorder Traversal...

## Construct Binary Search Tree from a given Preorder Traversal using Recursion

Objective: – Given a preorder traversal, construct BST from that. Input: Preorder traversal Similar Problem : This problem is similar to the – Construct Binary Search Tree from a given Preorder Traversal Using Stack...

## Print The Top View of a Binary Tree

Objective: – Given a binary tree, print it in Top View of it. What is Top View: Top view means when you look the tree from the top the nodes you will see will...

## Construct a Binary Tree from Given Inorder and Depth-First-Search.

Objective: – Given a inorder and preÂ­order traÂ­verÂ­sal, conÂ­struct a binary tree from that. Input: Inorder traversal and Depth-First-Search. Approach: int[] inOrder = { 8, 4, 2, 5, 1, 6, 3, 7, 9 }; int[]...

## Depth First Search/Traversal in Binary Tree

Objective: – Given a Binary Search Tree, Do the Depth First Search/Traversal . Appraoch: Approach is quite simple, use Stack. First add the add root to the Stack. Pop out an element from Stack...

## Inorder Predecessor and Successor in Binary Search Tree

Objective: – Given a Binary Search Tree, Find predecessor and Successor of a given node. What is Predecessor and Successor : When you do the inorder traversal of a binary tree, the neighbors of...

## Print All The Nodes Which are X distance from the Given Node

Objective: – Given Binary Tree, Print All The Nodes Which are X distance from the Given Node. Example : Approach: Quite Tricky solution, i will explain using the example given in the picture.

## Print All The Nodes Which are X distance from the Leaf Nodes

Objective: – Given Binary Tree, Print All The Nodes Which are X distance from the Leaf Nodes Example : Approach:

## Print All The Nodes Which are X distance from the Root

Objective: – Given Binary Tree, Print all the nodes which are X distance from the root Example : Appraoch:

## Find the Distance between Two Nodes of a Binary Tree.

Objective: – Given nodes in a binary tree, find the distance between them. Example : Approach:

## Find The Distance From Root To Given Node of a Binary Tree.

Objective: – Find The Distance From Root To Given Node of a binary tree. What does Distance means : It means number of edges between two nodes. Approach:

## Construct a binary tree from given Inorder and Postorder Traversal

Objective: – Given a inorder and postorder traversal, write an algorithm to construct a binary tree from that. This problem was asked in the Microsoft coding competition. Input: Inorder and postorder traversals Similar Problems:...