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
how binary codes are used


State in brief about the proxy server A proxy server also helps a lot since it hides the real IP addresses of users requesting resources outside the firewall. Finally, the

THE DIFFERENCE ENGINE - Pascaline The difference enigne was based on the mathematical principle of finite differences and was used to solve calculations based on large numbers

Compare and contrast symmetric & asymmetric encryption algorithms. Your response should contain a brief overview of the cryptographic basis for every type of algorithm, and a compa

Write "heterogeneous" functions If a program uses simulated, dynamically allocated multidimensional arrays, it becomes possible to write "heterogeneous" functions which don't h

Maria opened her authentic Mexican restaurant MiCazuela in Tucson inthe 1980s. It quickly became popular for the tasty food and use of fresh organicproduce and all-natural meats. L

failed logins to end

What is Collation Collation refers to a set of rules that verify how data is sorted and compared. Character data is sorted using rules that explain  the correct character se

Q. Drawback of indirect addressing? • Drawback of this scheme is that it needs two memory references to fetch actual operand. First memory reference is to fetch the actual addr