Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am working on a project in Java to give nonrecursive implementations of get() and put() for BST. Partial solution : Here is an implementation

I am working on a project in Java to give nonrecursive implementations of get() and put() for BST.

Partial solution : Here is an implementation of get():

public Value get(Key key)

{

Node x = root;

while (x != null)

{

int cmp = key.compareTo(x.key);

if (cmp == 0) return x.val;

else if (cmp < 0) x = x.left;

else if (cmp > 0) x = x.right;

}

return null;

}

The implementation of put() is more complicated because of the need to save a pointer

to the parent node to link in the new node at the bottom. Also, you need a separate

pass to check whether the key is already in the table because of the need to update the

counts. Since there are many more searches than inserts in performance-critical implementations,

using this code for get() is justified; the corresponding change for put()

might not be noticed.

I need three test on output.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

I don't know where the bug in this code. Please help me, thank you.

Answered: 1 week ago