Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The next questions refer to binary search used in the rank method in class BinarySearchST ( code seen below ) . Assume integer keys with

The next questions refer to binary search used in the rank method in class BinarySearchST (code seen below).
Assume integer keys with sorted keys array: int[] keys ={10,20,30,40,50,60,70}; So initially in rank lo =0 and hi=6.
For each of the next 10 questions the answer will be a number between -1 and 7.
public int rank(Key key)
{
int lo =0, hi =N-1;
while (lo hi)
{
int mid =l0+hi-loo2;
int cmp= key.compareTo(keys[mid]);
if (cmp0)hi=mid-1;
else if (cmp>0) lo =mid+1;
else return mid;
}
return lo;
}
Question 1: For binary search for 30 in the keys array, what is the final value of lo?
Question 2: For binary search for 30 in the keys array, what is the final value of hi?
Question 3: For binary search for 5 in the keys array, what is the final value of lo?
Question 4: For binary search for 5 in the keys array, what is the final value of hi?
Question 5: For binary search for 15 in the keys array, what is the final value of lo?
Question 6: For binary search for 15 in the keys array, what is the final value of hi?
Question 7: For binary search for 25 in the keys array, what is the final value of lo?
Question 8: For binary search for 25 in the keys array, what is the final value of hi?
Question 9: For binary search for 65 in the keys array, what is the final value of lo?
Question 10: For binary search for 65 in the keys array, what is the final value of hi?For binary search for 65 in the keys array, what is the final value of lo?
image text in transcribed

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

% of what amount is $1.00?

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago