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
The Towers of Hanoi Problem Towers of Hanoi problem is described. There are three pegs on which disks are "threaded" (there are holes in the disks to allow them to be placed on

Explain the key characteristics of mobile computing applications

Define race condition.  When several process access and manipulate similar data concurrently, then the outcome of the implementation depends on particular order in which the ac

What is the difference between latches and flip-flops based designs Latches are level sensitive whether flip-flops are edge sensitive. So, latch based design and flop based des

Question: (a) Briefly explain how the functionality of the WWW has been enhanced, after its birth at CERN site. Use examples to illustrate your answer. (b) Many modern com

What is cache memory? It is a small, fast memory that is inserted among large, slower main memory and the processor. It decreases the memory access time

Common Tasks to Accomplish: Once you've worried about what and why you're doing "AI", what has inspired you and how you're going to approach the job, then you just start to th

Define Hit ratio. The performance of cache memory is frequently measured in terms of quantity called hit ratio. Hit-Find a word in cache. Miss-Word is not found in cache.

I am the inventor of the railway signaling device now operated by timer. I wish to move on to the next phase where the equipment will be operated by DTMF codes. The device is a si

Describe the term- Systems Analysis A systems analysis team is every so often brought in to improve on an existing system. Often this involves moving from a paper-based filing