January 10, 2025 |4.7K Views

Print BST keys in the given range

  Share   Like
Description
Discussion

Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Print all the keys of the tree in range k1 to k2. i.e. print all x such that k1<=x<=k2 and x is a key of given BST. Print all the keys in increasing order. 
Example:

Graph:


Input: k1 = 10 and k2 = 22


Output: 12, 20 and 22.


Explanation: The keys are 4, 8, 12, 20, and 22.
So keys in range 10 to 22 is 12, 20 and 22.

Print BST keys in the given range: https://www.geeksforgeeks.org/print-bst-keys-in-the-given-range/