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
A queue is a, FIFO (First In First Out) list.

This question is based on the requirements of a system to record band bookings at gigs. (A 'gig' is an event at which one or more bands are booked to play). You do not need to know

Merge sort is a sorting algorithm which uses the basic idea of divide and conquers. This algorithm initially divides the array into two halves, sorts them separately and then merge

Write down any four applications of queues.            Application of Queue (i)  Queue is used in time sharing system in which programs with the similar priority form a queu

Q. Describe the representations of graph. Represent the graph which is given to us using any two methods Ans: The different ways by which we can represent graphs are:

#question bubble sort..

Q .  Write down the non-recursive algorithm to traverse a tree in preorder. Ans: T he Non- Recursive algorithm for preorder traversal is written below: Initially i

1. In computer science, a classic problem is how to dynamically store information so as to let for quick look up. This searching problem arises frequently in dictionaries, symbol t

RENDERING, SHADING AND COLOURING By introducing hidden line removal we have already taken one step away from wire-frame drawings towards being able to realistically model and d

Assume a complete binary tree T with n nodes where each node has an item (value). Label the nodes of the complete binary tree T from top to bottom & from left to right 0, 1, ..., n