-
Basic binary search. Given a sorted list of integers
arrand an integertargetthat is guaranteed to be inarr, write a functionbinary_search(arr, target)that returns the index oftargetinO(log n)time. Include loop invariants or a short explanation of why the algorithm is correct. (Based on the binary search exercise in Lecture 6.) -
Binary search trace. For the list
arr = [2, 5, 7, 9, 12, 16, 21, 27]andtarget = 16, show every iteration of binary search (low, mid, high, and the comparison result) until the target is found. State the number of iterations. (Based on Lecture 4’s binary search visualization.) -
Index of first False. An array of booleans starts with some
Truevalues followed byFalsevalues, e.g.,[True, True, True, False, False]. Write a function that returns the index of the firstFalseinO(log n)time using binary search. (Based on Lecture 9’s “find first false” exercise.) -
**Binary search with