In which of the cases uniform binary search fails compared to binary search?

2025

In which of the cases uniform binary search fails compared to binary search?

  1. A.

    A table lookup is generally faster than an addition and a shift

  2. B.

    Many searches will be performed on the same array

  3. C.

    Many searches will be performed on several arrays of the same length

  4. D.

    Complexity of code

Attempted by 7 students.

Show answer & explanation

Correct answer: D

Concept: Uniform binary search is a variant of binary search that precomputes, once per array length, the sequence of offsets between successive midpoints and stores them in a lookup table. Instead of recomputing the midpoint arithmetically as (low + high) / 2 on every iteration (an addition and a shift/divide), each step simply reads the next offset from the table and adjusts a single index. This trades per-step arithmetic for a one-time table-building cost.

Application: That trade only pays off under specific conditions -- when a table read is cheaper than an addition-and-shift on the target hardware, when the same array is searched repeatedly (so the table-building cost is paid once and reused), or when several different arrays share the same length (so one table serves all of them, since the offsets depend only on length, not on the array's contents). None of those three conditions is a weakness of uniform binary search -- they are precisely the scenarios it is designed to exploit.

Contrast the offered scenarios by what each actually means for the technique:

  • A table lookup being faster than an addition and a shift: favors the table-driven approach -- an advantage, not a failure.

  • Many searches performed on the same array: the table is built once and reused across all those searches -- again an advantage.

  • Many searches on several arrays of the same length: one table (built from length alone) serves every such array -- also an advantage.

Result: The one place uniform binary search comes out worse than plain binary search is in the code itself: it needs the extra machinery of precomputing and indexing into the offset table, on top of the search logic, whereas standard binary search only needs the simple average-the-bounds step. That added implementation overhead -- the complexity of the code -- is the genuine disadvantage, confirming the correct option.

Explore the full course: Coding For Placement

Loading lesson…