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

Spread the post

Binary search tree print Even level data using recursion

In this post we are learning about how to print Even 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

Live preview

Showing all bst Even level nodes in below.

BST Even level Data Print Even level BST nodes 15070309024011015365020101566080

Note data root at level zero (0).

Algorithm:

Time complexity of this program O(n)

Code execution:

Process to print even level BST Binary search tree print even level Stack Areamainroot(pointer)print_evenshow (int) =0temp(pointer)print_evenshow (int) =1temp(pointer)print_evenshow (int) =2temp(pointer)print_evenshow (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 Even level BST node .

C program to print all Even level BST nodes. Recursive approach.

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

Spread the post

Recommended Posts: