- a table lookup is generally faster than an addition and a shift, and
- many searches will be performed on the same array, or on several arrays of the same length
(Taken from http://en.wikipedia.org/wiki/Uniform_binary_search)
Just simply implemented in JS from original C source of Knuth's algorithm.
// target = [91, 97, 99, 101, 127, 129, 145] // will found index of 127 via optimized bin search algo. thinking... ----------------- middle of target: 3 127 is bigger than 101 127 is less than 129 127 at index: 4
Source: http://jsfiddle.net/VCtqD/1/
No comments:
Post a Comment