That's not really elogant...
By k, I assume you are talking about k=alen(arr) ?
You do find the maxium value in log time.
But I think it might be better, just to:
max_element = 0
max_index = 0
for k = alen(arr) to 1 step -1
if X >= arr(k)
max_element = arr(k)
endif
endfor
>test = arr[int(k/2)]
>if X < test && We don't need to check the rest of the array
> test = arr[int(k/4))
> if X < test && we don't need to check 3/4 of the array
> ...
> endif
>endif
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only