Let's implement a classic algorithm: binary search on an array.
Implement method named search that takes a SearchList as its first parameter and an Int as its second.
If the SearchList is empty you should throw an IllegalArgumentException.
SearchList is a provided class. It provides a get(Int) method that returns the Int at that index, and
a size method that returns the size of the SearchList. Those are the only two methods you should need!
You can also access the list elements using bracket notation just like a list or array: list[position].
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:
(start + end) / 2)truestart reaches the end, at which point you can give up and
return falseThis is a fun problem! Good luck! Keep in mind that every time you call SearchList.get or use bracket notation
that counts as one access, so you'll need to reduce unnecessary accesses to pass the test suite.
Specifically, you should only call list.get once per iteration, saving the result into a temporary variable.
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: