Recursive function , Data Structure & Algorithms

Q. Write down the recursive function to count the number of the nodes in the binary tree.   

Ans.

Recursive Function to count no. of Nodes in Binary Tree is written below

The number NUM of nodes in T is 1 greater than the number NULL of nodes in the left subtree of T plus the number NUMR of nodes in the right subtree of the T. Count( LEFT , RIGHT , ROOT , NUM.)

This procedure finds the number NUM of nodes in a binary tree T in memory.

1.  If ROOT = NULL, then : Set NUM := 0, & Return.

2.  Call COUNT( LEFT , RIGHT , LEFT[ ROOT], NUML).

3.  Call COUNT ( LEFT , RIGHT, RIGHT[ ROOT], NUMR).

4.  Set NUM := NUML +NUMR+1.

5.  Return.

 

 

 

Posted Date: 7/13/2012 2:16:34 AM | Location : United States







Related Discussions:- Recursive function , Assignment Help, Ask Question on Recursive function , Get Answer, Expert's Help, Recursive function Discussions

Write discussion on Recursive function
Your posts are moderated
Related Questions
write an algorithm to insert an element at the beginning of a circular linked list?

Q. Explain the various memory allocation strategies.                                                            Ans. M e m ory Allocation Strategies are given as follow

Warnock's Algorithm An interesting approach to the hidden-surface problem was presented by Warnock. His method does not try to decide exactly what is happening in the scene but

So far, we now have been concerned only with the representation of single stack. What happens while a data representation is required for several stacks? Let us consider an array X

example of stack using flowchart

Problem 1. Explain about the doubly linked list with neat diagram. Diagram Explaining doubly linked list 2. Explain what are the criteria to be used in evaluatin

Q. Illustrate the result of running BFS and DFS on the directed graph given below using vertex 3 as source.  Show the status of the data structure used at each and every stage.

The pre-order and post order traversal of a Binary Tree generates the same output. The tree can have maximum One node

What is binary search?   Binary search is most useful when list is sorted. In binary search, element present in middle of the list is determined. If key (the number to search)

Explain the theory of computational complexity A  problem's  intractability  remains  the  similar  for  all  principal  models  of   computations    and   all reasonable inpu