Suppose you are given an array Al1…n] of distinct numbers that you are told satisfies for some unknown. Such an array is known as unimodal (with the mode being a minimum). Give an O(log n) time algorithm for finding the min imum item Ali] in such an array. As an example, in the array below, the minimum item is 4. 9 5 4 6 8 12 14 To get full marks you must fully describe your algorithm (pseudocode is fine), explain why it returns a correct answer and show why it runs in O(logn ) time.
Don't use plagiarized sources. Get Your Custom Essay on
Problem 5 Suppose you are given an array A[1…nl of distinct numbers that you are told satisfies A…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
int minimum(int array1, int low, int n)
int min = array1[low];
for (i = low; i <= n; i++)
if (array1[i] < MIN)
min = array1[i];
The above code will return minimum value in Olog(n) time.
1) start from first value
2) loop n times
3) if value at position i is less then previous value then update minimum variable
4) end loop
for array : 10 8 6 4 5 7 9
start with min = array[low] that is 10.
compare 10 with next variable and update min if min < array[i]
so answer is 4