Consider the same code as given in above question. What does the function print() do in general?
The function print() receives root of a Binary Search Tree (BST) and a positive integer k as arguments.
(A) Prints the kth smallest element in BST
(B) Prints the kth largest element in BST
(C) Prints the leftmost node at level k from root
(D) Prints the rightmost node at level k from root
Explanation: The function basically does reverse inorder traversal of the given Binary Search Tree. The reverse inorder traversal produces data in reverse sorted order. Whenever a nod is visited, count is incremented by 1 and data of a node is printed only when count becomes k.
Quiz of this Question
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.