Recursive function , Data Structure & Algorithms

Assignment Help:

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.

 

 

 


Related Discussions:- Recursive function

Binary search, In a sorted list, Binary search is carried out by dividing t...

In a sorted list, Binary search is carried out by dividing the list into two parts depends on the comparison of the key. Since the search interval halves each time, the iteration o

Algorithmss, calculate gpa using an algorithm

calculate gpa using an algorithm

Write an algorithm of value in tax using pseudocode, A town contains a tota...

A town contains a total of 5000 houses. Every house owner has to pay tax based on value of the house. Houses over $200 000 pay 2% of their value in tax, houses over $100 000 pay 1.

Determine the area subdivision method, Area Subdivision Method In this ...

Area Subdivision Method In this method, the viewport is examined for clear decisions on the polygons situated in it, in regard to their overlap and visibility to the viewer. Fo

Splaying steps - splay trees, Readjusting for tree modification calls for r...

Readjusting for tree modification calls for rotations in the binary search tree. Single rotations are possible in the left or right direction for moving a node to the root position

Total impedent of the circuit, an electrical student designed a circuit in...

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

Arrays and pointers, C compiler does not verify the bounds of arrays. It is...

C compiler does not verify the bounds of arrays. It is your job to do the essential work for checking boundaries wherever required. One of the most common arrays is a string tha

Determine the stereo vision, Determine the stereo vision There is still...

Determine the stereo vision There is still one more major item missing, before we can look at a computer display or plot and perceive it just as we see a real object, namely th

ALGORITHMS, WRITE AN ALGORITHM TO READ TWO NUMBERS AND PRINT THE LOWER VALU...

WRITE AN ALGORITHM TO READ TWO NUMBERS AND PRINT THE LOWER VALUE

Hash tables, Q. Explain the Hash Tables, Hash function and Hashing Techniqu...

Q. Explain the Hash Tables, Hash function and Hashing Techniques properly?             A n s . H as h Table is explained as follows : A hash table is a data struc

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd