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. Learn synchronization principles? To learn synchronization subsequent dependencies are recognized:  i)  Data Dependency: These are RAW, WAW and WAR dependency.  ii) Co

Q. Create an input buffer ? CODE SEGMENT ... MOV AH, 0AH                       ; Move 04 to AH register MOV DX, BUFF                   ; BUFF must be defined in data

Program 'preemption' is? Ans. Forced de allocation of the CPU from a program that is executing on the CPU is called preemption program.

Explain difference between Scanning and parsing. Scanning and parsing: Scanning process is the process of recognizing the lexical components in a source string whereas parsin

In a DTMF phone, digits are represented by: (A)  Orthogonal frequencies. (B)  Orthogonal Phases. (C)  Orthogonal codes. (D)  Orthogonal pulses. Ans: Di

calculate the time complexity of a=(b/c) operation in stack

How congestion is controlled in TCP? One of the most significant aspects of TCP is a mechanism for congestion control. In main modern internets, extreme long delays or packet l

Explain about the Prepurchase Interaction activity. Prepurchase Interaction: This interaction for consumers comprises three activities: • Product or service search and di

RAM: Read / Write memory, High Speed, Volatile Memory. ROM: Read only memory, Low Speed, Non Voliate Memory.   RAM- Random Access memory it is a Volatile Memory.  volatil

State the SELECTIVE CLEAR - logic micro operations The selective-clear operation clears to 0 bits in register A only  where there are corresponding 1's in the register B. For