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
Algorithm for insertion of any element into the circular queue: Step-1: If "rear" of the queue is pointing at the last position then go to step-2 or else Step-3 Step-2: make

Given are the definitions of some important terms: 1) Field: This is an elementary data item characterized by its size, length and type. For instance, Name

Arrays :- To execute a stack we need a variable called top, that holds the index of the top element of stack and an array to hold the part of the stack.

1.Create a flowchart to show the process that will allow the implementation of Stack, Push, and Pop operations. 2.Create a flowchart to show the process that will allow the impleme

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

State about the Simple types - Built-In Types Values of the carrier set are atomic, that is, they can't be divided into parts. Common illustrations of simple types are inte

Thread By changing the NULL lines in a binary tree to special links known as threads, it is possible to perform traversal, insertion and deletion without using either a stack

what''s queue ?

write an algorithm for multiplication of two sparse matrices using Linked Lists