Current location - Training Enrollment Network - Books and materials - How to sort the book index?
How to sort the book index?
Sorting by index means that all the books are arranged in order, which can be imagined as the numbers 1, 2, … 100000. Dichotomy search is to compare the serial number corresponding to the book with the serial number in the middle, and compare the size with the initial 50 thousand. If it is less than 50000, all numbers between 5000 1 and 65438+ million are excluded. The second time, look for it between 1 and 49999. It only takes 10 milliseconds to exclude half of the serial number.

In this way, after 10 milliseconds, at most half of the serial number remains;

After 20 milliseconds, at most 1/4 serial number remains;

After 30 milliseconds, at most 1/8 serial number remains;

……

After170ms, the serial number of 1/2 17 remains at most.

And 210 =1024,27 =128, so 217 =128 *1024 >100000.

In other words, after 170 milliseconds, there is no serial number, and all searches are completed.