
This updated information has been further expanded upon on my new website. You can find the updated details here: https://k5kc.com/cs/algorithms/find-local-minima-in-a-given-array/.
Problem: Given an array ‘a’ of N distinct integers, design an
O(log N) algorithm to find a local minimum: an index i such that a[i-1]
> a[i] < a[i+1].
Examples:
a = [1,2,3,4,5] (increasing, increasing) a[0] is an LM
a = [5,4,3,2,1] (decreasing, decreasing) a[n] is an LM
a = [1,2,2,2,1] (increasing, decreasing) a[0] and a[n] are LMs
Solution:
Brute...