Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assume we already have class for binary search tree called BinarySearchT , you have access to the following methods (assume they are coded) public class

Assume we already have class for binary search tree called BinarySearchT,

you have access to the following methods (assume they are coded)

public class BSTNode { public int key; public E value; public BSTNode left; public BSTNode right; } public class BinarySearchT { private BSTNode root; public void insert(int key, E value) { ... } public void delete(int key) { ... } public  find(int key) { ... } }

you are asked to only code a method public int treeH() to the BinarySearchT class that computes the height of the tree.

Hint: You can use a helper method.

Hints:

you should use a helper function

I would do it with recursion

the key and value has no effect on this

remember what is the definition of the height with respect the depths of nodes

you can use Math.max(a,b) that would return the max between a and b, but if you prefer, you also can do it with loops

Note: make sure the name of the method matches

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

List and define the steps in the business buying decision process.

Answered: 1 week ago