Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle (4)
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00665368
Message ID:
00665442
Views:
30
Right. I'm still thinking on the problem (though I should work :)

The idea would be to check arr[k]*2 with X and arr[k] with X, there k is the middle number.



>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
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform