Spread the post

Sum of leaf node at min level

Leaf node are not contain any child node. now in this post we are learning about how to find sum of leaf node at minimum level.

Suppose Given Tree contain following nodes [ 9 5 17 15 25 20 30 ].

<95Blue Leaf nodesRed circle are min level1715252030

View insertion process.

Try it yourself

In this tree clear blue are leaf node. and red circle indicates minimum level leaf node.

Minimum level are two node [20,30] and sum of this leaf nodes are [ 50 ].


Hint: Count height of tree first.

C program to Sum of minimum level leaf node.


Code execution: view code execution process.

Stack Areamainheight (int) =3result (int) =50root(pointer)min_level_sumheight (int) =3level (int) =0result(pointer)temp(pointer)min_level_sumheight (int) =3level (int) =1result(pointer)temp(pointer)min_level_sumheight (int) =3level (int) =2result(pointer)temp(pointer) Heap Areastruct Treedata (int)= 9left_child (pointer) right_child (pointer) struct Treedata (int)= 5left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 17left_child (pointer) right_child (pointer) struct Treedata (int)= 15left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 25left_child (pointer) right_child (pointer) struct Treedata (int)= 20left_child (pointer)= NULLright_child (pointer)= NULLstruct Treedata (int)= 30left_child (pointer)= NULLright_child (pointer)= NULL

Note that not given all step of execution process here. view more.

Try it yourself

Spread the post

Recommended Posts: