I want to create a recursion pseudocode that will executed in O(logn) complexity and i want it to find the lower f(i) < 0 and f[1....n] which f(1) >0 and f(n)<0
prodedure fanc(A[n] , p , q ) //(this is my array,first digit of A ,last digit of A)
if A[n/2] >= 0
return fanc(A[n/2] , A[n/2] , A[n-1])
else
return fanc(A[n/2] , A[0] , A[n/2 -1])
if p<q
print p
else
print q
I know that somehow i have to end the recursion. Also i would like to know if i am in the correct path and if u have any good thoughts for this problem!
Better text of assignment copied from https://stackoverflow.com/questions/42935621/algorithm-in-ologn:
Let an integer function f:{1,2,3...n} be monotonic and defined in {1,2,3...n} and suppose that f(1) > 0 and f(n) < 0. We would like to find the smallest integer i with f(i) < 0. Design an algorithm for this purpose that run in O(logn).