Check if a Binary Tree is a Binary Search Tree (BST) using Property of Binary Tree: For a BST, all left nodes should be less than or equal to current node and current node must be less than all right nodes.
Trees and Graphs
Check if a Binary Tree is Balanced in O(N) time complexity.
Assumption: Heights of two subtrees of any node should never differ by more than one, to consider a tree as balanced.
Create a binary search tree with minimal height from a sorted increasing order array.
Recursively find the difference between the sum of nodes at odd levels and sum of nodes at even levels of a binary tree.
Given a binary tree, create a linked list of all nodes at each level of binary tree using recursion.
If there are n levels, there will be n linked lists.
You can create an ArrayList of linked lists.
Given a binary tree, create a linked list of all nodes at each level of binary tree without using recursion.
If there are n levels, there will be n linked lists.
You can create an ArrayList of linked lists.
Given a binary tree with an integer data element; find all paths whose sum of data nodes will be equal to a given value.
Path can start or end anywhere in the tree.
Example: If the sum given is 5 and a path is 2->3->1>-1....
Problem
Given a binary tree, find out if it is a binary search tree or not.
Approach 1
- You can traverse the tree in in-order way, and see if the elements are...