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
Q. Explain RBY and CMYK colour Printing? For good printing printers don't use RBY in place of that they use CMYK (Cyan instead of Blue, Magenta instead of Red, Yellow and a sep

What is the difference between the following two lines of Verilog code? #5 a = b; a = #5 b; #5 a = b; Wait five time units before doing the action for "a = b;". Value assig

All digital devices are made from circuits whichcan be switched between two possible states.These two states are represented by a voltagelevel at the output of the circuit e.g. 0V

Q. How many instructions in a Computer? A computer can have a vast number of instructions and addressing modes. Older computers with the growth of Integrated circuit technolog

Explain about the value chain for a manufactured product. The products sold in shops and purchased for use within organizations are the result of a complicated web of relations

The Chocolate Delights Candy Company requires to add the following functionality to its cash register: When a customer is checking out, the cash register requires keeping the ne

Question: a) Why do we use the Internet as the new distribution channel for e-banking products and services? b) In the context of e-banking or e-commerce, outline some o

Syntax and Semanticsx and Semantics for First-order logic - artificial intelligence: Propositional logic is limited  in its expressiveness: it may just represent true and false

What are threaded binary trees? A Threaded Binary Tree is a binary tree in which each node that does not have a right child has a THREAD (in real sense, a link) to its INORDER

Q. Illustrate the history of computers? Let's now consider history of computers since this will give fundamental information about technological development trends in computer