subject

Let's implement a classic algorithm: binary search on an array. Implement a class named BinarySearcher that provides one static method named search. search takes a SearchList as its first parameter and a Comparable as its second. If either parameter is null, or if the SearchList is empty, you should throw an IllegalArgumentException. SearchList is a provided class. It provides a get(int) method that returns the Comparable at that index, and a size method that returns the size of the SearchList. Those are the only two methods you should need! search returns a boolean indicating whether the passed value is located in the sorted SearchList. To search the sorted SearchList efficiently, implement the following algorithm: Examine the value in the middle of the current array (index (start + end) / 2) If the midpoint value is the value that we are looking for, return true If the value that we are looking for is greater than the midpoint value, adjust the current array to start at the midpoint if the value that we are looking for is less than the midpoint value, adjust the current array to end at the midpoint Continue until you find the value, or until the start reaches the end, at which point you can give up and return false This is a fun problem! Good luck! Keep in mind that every time you call SearchList. get that counts as one access, so you'll need to reduce unnecessary accesses to pass the test suite.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 22:30
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
question
Computers and Technology, 23.06.2019 23:30
What are "open-loop" and "closed-loop" systems
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Could you find out how im still getting an 83 percent on this in edhesive a = input("enter an animal: ") s = input ("enter a sound: ") e = "e-i-e-i-o" print ("old macdonald had a farm, " + e) print ("and on his farm he had a " + a + "," + e) print ("with a " + s + "-" + s + " here and a " + s + "-" + s + " there") print ("here a " + s+ " there a " + s) print ("everywhere a " + s + "-" + s ) print ("old macdonald had a farm, " + e)
Answers: 2
question
Computers and Technology, 25.06.2019 11:30
The function of network switch is to
Answers: 1
You know the right answer?
Let's implement a classic algorithm: binary search on an array. Implement a class named BinarySearch...
Questions
question
Chemistry, 06.05.2020 17:09
question
Mathematics, 06.05.2020 17:09
question
Mathematics, 06.05.2020 17:09
question
Biology, 06.05.2020 17:09
question
Mathematics, 06.05.2020 17:09
question
Social Studies, 06.05.2020 17:10
question
Mathematics, 06.05.2020 17:10
question
Mathematics, 06.05.2020 17:10
Questions on the website: 13722361