Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java public boolean BinarySearch(int first, int last, int item) { int mid = (first+last)/2; if (first > last) return false; if (item == a[mid]) return

Java
public boolean BinarySearch(int first, int last, int item) {
int mid = (first+last)/2;
if (first > last) return false;
if (item == a[mid]) return true;
if (item
if (item > a[mid]) return BinarySearch(mid+1, last, item);
return false;
}
image text in transcribed
image text in transcribed
public boolean BinarySearch(int first, int last, int item) int mid - (first+last) /2; if (first> last) return false; if (itema [mid]) return true; if (item a [mid]) return BinarySearch (mid+1, last, item) return false; Let's discuss it - it's a recursive function and it returns a boolean value And, then let's incorporate it in our ListArrayMain program to test it. Homework: 1. Set up an array of 100000000 (one hundred million!!) from 1 to 100000000 and search for an integer that is NOT in the array and time it to find out how long it takes to find it. Compare the binarv search time with the linear search time. Do this several times to see if binary search is really faster. ON PAPER, report on the running times that compare Binary and Linear search. You may have to look up how to time the execution of a Java program You may lose points if your report is illegible or grammatically incorrect or incomplete. 2. Write ON PAPER another binary search method - say, BinarySearch2, which returns the actual cell number where the item is found- or returns -1 if it's not found

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

=+a For what range of unit sales will Rainbow Rugs prefer option 1?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago