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
Soundness - artificial intelligence: You may see in some application domains-for example automated theorem proving - that your search is "sound and complete". The soundness in

Explain Circular Dependencies. Circular Dependencies: To know the problem of circular dependencies consider a file server which uses a timeserver to acquire the current

Write an applet that sets the background colour to cyan and foreground colour to red and displays a message that illustrates the order in which various applet methods are called wh

1. Figure 1 below shows the truth table for five different functions. Each truth table shows the inputs x1, x2 and the desired output d. (a) Write down which of these functions

Q Write a menu driven program to perform subtraction in base 5 using r and (r-1) complement with necessary validations.

Procedure Level Here, parallelism is accessible in the form of parallel executable procedures. In this situation, the design of the algorithm plays a main role. For example eac

Why cyclomatic complexity is important? Cyclomatic complexity is computed using a graph that verifies the control flow of the program. The nodes of the graph correspond to the

Stencil Duplicating Equipment Required Stencil Duplicator Thermal copier (optional) Electronic stencil cutter Materials Stencil COPY paper Ink Clean

Explain about the postpurchase interaction briefly. Postpurchase Interaction: Customer support and service: The considerations at such can be explained by the followin

Discuss about the Bus and Memory Transfer A read action implies transfer of information to outside environment from a memory word, whereas storage of information inside memory