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.

Distance from root to given node
Distance from root to given node

Approach:

Read moreFind The Distance From Root To Given Node of a Binary Tree.

Lowest Common Ancestor in a Binary Search Tree.

Objective: Find the Lowest Common Ancestor of two given nodes in a Binary Search Tree

What is Lowest Common Ancestor

In a given binary tree, The lowest common ancestor of two nodes n1 and n2 will be a node X such that node X will be the lowest node who has n1 and n2 as its descendants.

Similar Problem: Lowest Common Ancestor in a Binary Tree ( Not Binary Search Tree).

Example:

Lowest-Common-Ancestor-BST
Lowest-Common-Ancestor-BST

Input: A binary Search Tree and two nodes n1 and n2.

Appraoch:

Read moreLowest Common Ancestor in a Binary Search Tree.

Given a binary tree, find out the maximum sum of value from root to each leaf.

Objective: Find the maximum sum leaf to root path in a Binary Tree. Means in all the paths from root to leaves, find the path which has the maximum sum.

Input: A binary tree

Example:

Maximum Sum Leaf to Root pathApproach:

Read moreGiven a binary tree, find out the maximum sum of value from root to each leaf.

Given a Sorted Singly Linked List Array, Convert it into a Balanced Binary search Tree.

Given a Sorted Array, Convert it into its Balanced Binary search TreeObjective: You have been given a sorted singly List, you need to convert it into balanced binary search tree.

Why balanced binary tree is important:

You can also create the first node as root and insert all other nodes to the right of the tree because List is in increasing order but this constructed tree won’t be a balanced tree, it will be the skewed tree and to perform operations on this tree will be O(n), not O(logn).

Input: An sorted Singly Linked List

Output: Balanced Binary Tree

Example:

Singly Linked List To BST
Singly Linked List To BST

Approach:

Read moreGiven a Sorted Singly Linked List Array, Convert it into a Balanced Binary search Tree.