searching algorithm enquiry
请教PROGRAMMING高手们:
If i divide the interval I=[0,1) into, say, 64 subintervals, and recode the 64 left pts into an Array A[0:63] in ascending order, how can I decide which interval a random number a (- [0,1) is in with the LEAST possible loopings?
The method I use now is : start from the centre A[33], check if a>A[33]. if yes, check the centre of the upper half
if a>A[49]; else check centre of the lower half if a>A[17]. So on and so forth, just like the idea of a binary ADC converter. but i need 6 looping interation in order to get the answer. Any one knows faster method than this?
If i divide the interval I=[0,1) into, say, 64 subintervals, and recode the 64 left pts into an Array A[0:63] in ascending order, how can I decide which interval a random number a (- [0,1) is in with the LEAST possible loopings?
The method I use now is : start from the centre A[33], check if a>A[33]. if yes, check the centre of the upper half
if a>A[49]; else check centre of the lower half if a>A[17]. So on and so forth, just like the idea of a binary ADC converter. but i need 6 looping interation in order to get the answer. Any one knows faster method than this?