Professional Documents
Culture Documents
In a nutshell, this search algorithm takes advantage of a collection of elements that is already
sorted by ignoring half of the elements after just one comparison.
Compare x with the middle element.
If x matches with the middle element, we return the mid index.
Else if x is greater than the mid element, then x can only lie in the right (greater) half subarray
after the mid element. Then we apply the algorithm again for the right half.
Else if x is smaller, the target x must lie in the left (lower) half. So we apply the algorithm for the
left half.
Output:
Write a function that takes in an array of integers and returns an array of length 2 representing
the largest range of numbers contained in that array.
The first number is the output array should be the first number in the range while the second
number should be the last number in the range.
A range of numbers is defined as a set of numbers that come right after each other in the set of
real integers.
For instance, the output array [2, 6] represent the range {2, 3, 4, 5, 6}, which is the range of
length 5. Note that numbers do not need to be ordered or adjacent in the array in order to
form a range.
Pas 3