Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Recursive tree algorithms

Algorithms to Write:

1. Write a recursive function to determine if a binary tree is a binary search tree.  For example, in the trees above, the tree on the left is a binary search tree, while the tree on the right is not.

1889_Recursive tree algorithms.png              1562_Recursive tree algorithms1.png

120_Recursive tree algorithms2.png

2. The location of a node in a binary search tree is defined as a string such as LLRRL, which represents the node that you find by starting at the root, and traversing Left, traverse Left, traverse Right, traverse Right, and traverse Left.   Write a function to print a path to some target 'x' based on the direction from the root to the target.  For example, in the tree above, the path from 65 to 52 is LRR. Hint: use a stack to store the path.

3. Write a recursive algorithm to count the number of right children in a binary search tree.

4. 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);

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.

2176_Recursive tree algorithms3.png

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.

5. Write a recursive algorithm to delete the leaves of a binary tree.

Programming Requirements

You must use the binary search tree code provided.  Each algorithm must be implemented as both a private method and a public method of the class.  Your code will be tested using the program provided.

Other Requirements 

  • File names must match exactly to the file names provided
  • Clearly state any additional assumptions you may need to make.

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M9716263
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Data Structure

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As