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

Define File organization''s and it''s types

The searching method are applicable to a number of places in current's world, may it be Internet, search engines, text pattern matching, on line enquiry, finding a record from data

The process of accessing data stored in a serial access memory is same to manipulating data on a By using stack  method.

Example: Insertion of a key 33 into a B-Tree (w/split) Step 1: Search first node for key closet to 33. Key 30 was determined. Step 2: Node pointed through key 30, is se

Write an algorithm for compound interest.

Inorder traversal: The left sub tree is visited, then the node and then right sub-tree. Algorithm for inorder traversal is following: traverse left sub-tree visit node

Q. Draw  the structures of complete  undirected  graphs  on  one,  two,  three,  four  and  five vertices also prove that the number of edges in an n vertex complete graph is n(n-1

Range: A Structured Type in Ruby Ruby has a numerous structured types, comprising arrays, hashes, sets, classes, streams, and ranges. In this section we would only discuss rang

I need a person who has a good background in using R. Studio? In adition, a person who is good in using algorithms.