# Methods on Tree

\$30.00

Category:
Rate this product

Tree
1. Mirror Mirror:
Given a binary tree, convert it into its mirror.
Sample Input:
10
/ \
20 30
/ \
40 60
Sample Output:
10 10
/ \ Mirror / \
20 30 —> 30 20
/ \ / \
40 60 60 40
Inorder Traversal of mirror: 30 10 60 20 40
2. Level Max:
Given a binary tree, find the largest value in each level.
Sample Input:
4
/ \
2 9
/ / \
7 3 5
Sample Output: 4 9 7
Explanation:
There are 3 levels in the tree
Level 0: {4}, max = 4
Level 1: {2, 9}, max = 9
Level 2: {3, 5, 7}, max = 7
3. Inorder Successor:
Given a BST, and a reference to a Node x in the BST, find the Inorder
Successor of the given node in the BST.
DO NOT USE LIST
Sample Input:
20
/ \
8 22
/ \
4 12
/ \
10 14
x = reference of the node containing 8
Sample Output: reference of the node 10
Explanation:
The inorder successor of a parent node is the smallest (leftmost) node in
the right subtree. The leftmost node in the right subtree of parent node 8 is
10.
Another explanation is that, the inorder traversal of the given tree:
4 8 10 12 14 20 22
Hence, the inorder successor of 8 is 10.
4. Kth Smallest:
Given a Binary search tree, your task is to complete the function which will
return the Kth smallest element without doing any modification in the
Binary Search Tree.
DO NOT USE LIST
Sample Input:
20
/ \
8 22
/ \
4 12
/ \
10 14
k = 2
Sample Output: 8