Learn basic concept of c , c++ and python programming in regularcodes.com

Print BST keys given Range

How to print binary search tree in given range? here include few example to clear. suppose following data are inserted on binary search tree [150, 70, 30, 90, 240, 110, 153, 650, 20, 10, 15, 660, 80].

Try it Yourself

Exmaple 1: BST Data Between [70 - 100].

BST Data Between [ 10 - 100 ].

Example 3: BST Data Between [ 105 - 300 ] is : [ 110 150 153 240 ].

Example 4:BST Data Between [ 310 - 700 ] is : 650 660

Accepted Output

Given BST tree node is:

50, 30, 70, 20, 35, 60, 90, 10, 85, 100, 15, 80

Result :

BST Data Between [70 - 100] is : 70 90 85 100 80

BST Data Between [0 - 70] is : 50 30 70 20 35 60 10 15

Given BST tree node is:

150, 70, 30, 90, 240, 110, 153, 650, 20, 10, 15, 660, 80

Result :

BST Data Between [ 10 - 100 ] is : 10 15 20 30 70 80 90

BST Data Between [ 105 - 300 ] is : 110 150 153 240

BST Data Between [ 310 - 700 ] is : 650 660

Algorithm and code ececution

Given algorithm and process to print all BST keys in given range.

Execution process

Time complexity of this program O(n)

C program to print BST keys in given range.

Output
```  BST Inorder Data Is :  10  15  20  30  70  80  90  110  150  153  240  650  660
BST Data Between [ 10 - 100 ] is : 10 15 20 30 70 80 90
BST Data Between [ 105 - 300 ] is : 110 150 153 240
BST Data Between [ 310 - 700 ] is : 650 660 ```

Try it Yourself