## Maximum Depth of Binary Tree Leetcode Solution

Problem Statement   In the problem a binary tree is given and we have to find out the maximum depth of the given tree. A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 3 / …

## Iterative Inorder Traversal of a Binary Tree

In “Iterative Inorder Traversal of a Binary Tree” problem we are given a binary tree. We need to traverse it in inorder fashion “iteratively”, without the recursion. Example   2 / \ 1 3 / \ 4 5 4 1 5 2 3 1 / \ 2 3 / \ 4 …

## Morris Inorder Traversal

We can traverse a tree in the inorder fashion iteratively, using stack, but it consumes space. So, in this problem, we are going to traverse a tree without the linear space being used. This concept is called Morris Inorder Traversal or Threading in Binary trees. Example 2 / \ 1 …

## Sum of Left Leaves Leetcode Solutions

In this problem, we have to find the sum of all left leaves in a binary tree.  A leaf that is called a “Left Leaf” if it is a left child of any node in the tree. Example     2 / \ 4 7 / \ 9 4 Sum is 13 …

## Morris Traversal

Morris traversal is a method to traverse the nodes in a binary tree without using stack and recursion. Thus reducing the space complexity to linear. Inorder Traversal   Example 9 7 1 6 4 5 3 1           /    \         2    …

## Kth ancestor of a node in binary tree

Problem Statement   The problem “Kth ancestor of a node in binary tree” states that you are given a binary tree and a node. Now we need to find the kth ancestor of this node. An ancestor of any node is the nodes that lie on the path from the root …

## Find postorder traversal of BST from preorder traversal

Problem Statement   The problem “Find postorder traversal of BST from preorder traversal” states that you are given preorder traversal of a binary search tree. Then using the given input find the postorder traversal. Example      preorder traversal sequence: 5 2 1 3 4 7 6 8 9 1 4 3 …

## Iterative Preorder Traversal

The problem “Iterative Preorder Traversal” states that you are given a binary tree and now you need to find the preorder traversal of the tree. We are required to find the preorder traversal using iterative method and not the recursive approach. Example     5 7 9 6 1 4 3 …

## Boundary Traversal of binary tree

Problem Statement   The problem “Boundary Traversal of binary tree” states that you are given a binary tree. Now you need to print the boundary view of a binary tree. Here boundary traversal means that all the nodes are shown as the boundary of the tree. The nodes are seen from …

## Diagonal Traversal of Binary Tree

Problem Statement   The problem “Diagonal Traversal of Binary Tree” states that you are given a binary tree and now you need to find the diagonal view for the given tree. When we see a tree from the top-right direction. The nodes which are visible to us is the diagonal view … 