**Objective: –** Given a binary tree with three pointers left, right and nextSibling). Write the program to provide the nextsibling pointers.

This problem can also be referred as “**Populating Next Right Pointers in Each Node**”

**Example:**

**Approach:**

Objective: Given a binary tree and a given number x, Write an recursive algorithm to search the element in the tree. This is one of the very basic problems of tree. If you are new to binary trees, this problem might help you to understand the tree. First we will see the recursive solution then … Read more

There are multiple ways to in which you can traverse a tree. In this article we will see these traversals in detail. If you are new to trees then I would recommend that you pay close attention to this article because you will be solving almost all the problems on tree by using one or … Read more

Objective: Given a binary tree, Write an non-recursive algorithm to find the size of the tree. Note : Size of the tree is number of nodes in the tree Approach: In our earlier post (link) we have seen the clean and simple recursive approach for finding the size of the tree. Now we will see how … Read more

Breadth-First Search ( or Traversal) also know as Level Order Traversal. What is Breadth First Search: Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbors. (Reference – Wiki) Example: … Read more

Objective: – Given a binary tree, Find the deepest left node in it. Approach: This approach is very similar to “Find the Deepest Node in a Binary Tree” with little modification. Take two global variable as “deepestlevel” and ” deepLeftNode“. starting with level=0, Do the inorder traversal and whenever you go down one level ( … Read more

Objective: – Given a binary tree , Find the max element in it. Example: Approach: Use Recursion. Max will the Max(root, max element in the left subtree, max element in right subtree) Recursively solve for the max element in the left subtree and right subtree. Complete Code:Run This Code Output: Max element in Binary Tree: 35

**Objective: –** Given a binary tree with three pointers left, right and nextSibling). Write the program to provide the nextsibling pointers.

This problem can also be referred as “**Populating Next Right Pointers in Each Node**”

**Example:**

**Approach:**

**Objective: –** Given two binary trees check if they are mirror image of each other.

**Example:**

**Approach:**

**Objective: –** Given a binary tree and X, write an algorithm to Print all the paths starting from root so that sum of all the nodes in path equals to a given number.

**Example:**

**Objective: –** Given a binary tree, write an algorithm to find the diameter of the tree.

**What is Diameter Of a Tree: **Diameter of tree is defined as *A longest path or route between any two nodes in a tree. The path may or may not for through the root. *

**Example:**

** **

**Approach:**

**Objective: –** Given a binary tree, write an algorithm to Find the deepest node in it.

**Approach: **

- Take two global variable as “
” and “*deepestlevel*“.*value* - starting with
=0, Do the inorder traversal and whenever you go down one level ( root.left OR root.right), increase the level by 1.*level* - Keep checking if
, if yes then update the “*deepestlevel < level*” and “*deepestlevel*“.*value* - At the end return “
“, which will the deepest node value.*value* - See the code for better explanation.

Objective: Given a binary tree, print all nodes will are full nodes. Full Nodes: Nodes Which has both the children, left and right are called Full Nodes Approach: quite simple Solution. Do the any of the traversal (inorder, preorder, postorder etc). During traversal, check the node if it has left child and right child, If … Read more

**Objective:** **– **Given a binary tree, print it in Bottom View of it.

*What is Bottom View: **Bottom view means when you look the tree from the bottom the nodes you will see will be called the bottom view of the tree. See the example below.*

*as you can see in the example above,8, 4, 9, 5, 3, 7 is the bottom view of the given binary tree.*

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 at any node differ by at most 1. At anytime if height difference becomes greater than 1 then tree balancing is … Read more

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 }; int[] levelOrder = { 1, 2, 3, 4, 5, 6, 7 }; First element in the levelorder [] will be the … Read more