Binary search is broken (most of the time)...

| | Comments (2)

Very interesting gem on binary seaches.

(via Bill de hÓra).

2 Comments

M.Schwarz said:

I would say this is a limitation, not a Bug.
The C/C++ replacement line
> mid = ((unsigned) (low + high)) >> 1;
is not able fix this bug, the limitation (number of elements in the binary tree) is just doubled, not sufficient if array index is an unsigned int.
A
> mid = ((size_t) low + (size_t) high) >> 1;
would be needed then here.

Even more interesting:
Bserach only works with unique key values, else its not garantueed to return the first entry of the search value (qsort has no prob with multiple keys)

Matthias, of course, it's not a bug in the binary search algorithm, it's a limitation of the runtime environment the binary search algorithm is running in.

About this Entry

This page contains a single entry by HMK published on June 6, 2006 5:32 PM.

Automating "All" Tests was the previous entry in this blog.

World Cup Envy is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.