Write a recursive algorithm, Computer Engineering

Write a recursive algorithm to count the number of right children in a binary search tree.

Write the method levelCount whose header is given below. Method levelCount returns the number of nodes on the specified level.

int BinarySearchTree :: levelCount(BinaryNode* t, int level);

1770_Write a recursive algorithm.png

For this problem, the root is at level zero, the root's children are at level one, and for any node N its level is one more than N's parent's level. For example, for the bean-tree diagrammed below, the call levelCount(t,1) should return 2 (chickpea and navy are on level 1); the call levelCount(t,2) should return 3; and the call levelCount(t,4) should return 0.

Hint: when the level is 0, there is always just one node at that level, the root node (assuming it isn't empty), so return 1. If the level isn't zero, recursive calls will be used to determine the number of nodes at the requested level, and the level-requested should change in the recursive calls.

Posted Date: 4/2/2013 1:27:27 AM | Location : United States

Related Discussions:- Write a recursive algorithm, Assignment Help, Ask Question on Write a recursive algorithm, Get Answer, Expert's Help, Write a recursive algorithm Discussions

Write discussion on Write a recursive algorithm
Your posts are moderated
Related Questions
State the Tips of timescale directive Include a `timescale directive at the top of each module, even if there are no delays i n the module, since some simulators may require th

Case Study - A taxi company has 200 taxies. The company provides its services to all the nine districts in Mauritius, about 20 taxies per district. A taxi is normally attached to

In the first part of Assignment 2A you will develop a simple Patient class, representing an Patient who is to be admitted for a minor procedure that only requires a 1-2 day stay in

Q. Example on Cyclic Distribution of data? !HPF$ PROCESSORS P1(4) !HPF$ TEMPLATE T1(18) !HPF$ DISTRIBUTE T1(CYCLIC) ONTO P1 The result of these instructions is display

Analysis of Algorithms For this task, each student should do two things: An empirical analysis of the runtime and comparisons made for all algorithms as a function of input si

Described virtual memory Ans: Data is to be stored in physical memory locations that have addresses different from those that specified by the program. The memory control circu

How will you form an 8 bit adder using 2 four bit adder IC's 7483? Ans: 4 bit adder IC is IC 7483. This has two four bit data inputs and output carry, 4 bit data output carr

Discuss two main approaches to reuse free memory area in a heap. Two major approaches to reuse free memory area in a heap are: First-fit: Allocate the first hole which i

Q. F' (A, B, C, D) = (A + B + D')(A + C' + D')(A + B' + C')        D' (A, B, C, D) = (A + B' + C + D')(A' + C' + D')(A' + B + D)        Find the simplified function F and imple

Q. Show the Classification of Printers? Printers can be classified on following bases: a) Impact: Impact printers print by impact of hammers on ribbon (for example Dot-Matri