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

Spread the post

Binary search tree print Odd level data using recursion

In this post we are learning about how to print Odd level data in given bst. assume that following data are inserted on tree [150, 70, 30, 90, 240, 110, 153, 650, 20, 10, 15, 660, 80].

BST Tree BST to find odd level data. 15070309024011015365020101566080

Click to view insertion process.

Live preview

Showing all bst odd level nodes in below.

BST Odd level Data Print odd level BST nodes 15070309024011015365020101566080

Note that tree root node are at level 0.

Algorithm:

Execution process:

Find odd level node Process to find odd level data in BST Stack Areamainroot(pointer)print_odd_levelshow (int) =1temp(pointer)print_odd_levelshow (int) =2temp(pointer)print_odd_levelshow (int) =3temp(pointer) Heap Areastruct Treedata (int)= 150left_child (pointer) right_child (pointer) struct Treedata (int)= 70left_child (pointer) right_child (pointer) struct Treedata (int)= 30left_child (pointer) right_child (pointer)= NULLstruct Treedata (int)= 90left_child (pointer) right_child (pointer) struct Treedata (int)= 240left_child (pointer) right_child (pointer) struct Treedata (int)= 110left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 153left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 650left_child (pointer)= NULLright_child (pointer) struct Treedata (int)= 20left_child (pointer) right_child (pointer)= NULLstruct Treedata (int)= 10left_child (pointer)= NULLright_child (pointer) struct Treedata (int)= 15left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 660left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 80left_child (pointer)= NULLright_child (pointer)= NULL

In this execution process not imagination all steps. below link click and view how to insert bst node, how to show all bst node and how to print all odd level BST node .

C program to print odd level BST nodes. Recursive approach.

Output
 BST Inorder Data Is :  10  15  20  30  70  80  90  110  150  153  240  650  660
 Odd Level Nodes Is :10 30 90 153 650 150 

Spread the post

Recommended Posts: