Binary vs. jump search: the target determines which probes less

The article asks why jump search can read fewer array values than binary search despite binary search's O(log n) worst case. Comparing searches for 2 and 46 in a sorted array of 32 even numbers shows the winner depends on the target. For 2, jump search needs only two reads while binary search needs five. For 46, binary search needs five reads while jump search needs eight. The author provides JavaScript traces that record each array read and whether the target was found. The piece also notes that jump search's worst case is O(√n) and that these results count reads rather than measuring elapsed time.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in