Describe an algorithm relying only on the BinaryTree operati

Describe an algorithm, relying only on the BinaryTree operations, that counts the number of leaves in a binary tree that their parents are the right children of a node. Use Pseudo-code to explain.

Solution

Answer:

Here is the recurrsive program to count the number of leaves :

NL(T ) = 1 , T is leaf

   = NL(LST ) + NL(RST) , otherwise

int NL( structure node *t)

{

if( t = = NULL)

if ( t--> left == NULL && t--> right = = NULL )

return 1;

else

return ( NL(t-->left) + NL(t-->left

NL = Non- leaves

LST = Left Sub Tree

RST = Right Sub Tree

Describe an algorithm, relying only on the BinaryTree operations, that counts the number of leaves in a binary tree that their parents are the right children of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site