Compare searches that stop at different positions

Two implementations search the following eight-entry array for a target identifier:


[14, 27, 35, 48, 63, 72, 86, 91]


Forward searches from the first entry toward the last. Reverse searches from the last entry toward the first. Each implementation performs one equality test per inspected entry and stops immediately when it finds the target. If the target is absent, it inspects all eight entries.


The comparison count is the number of equality tests performed. Complete the table with exact integer counts. In the final column, enter Forward, Reverse, or Tie to identify which implementation performs fewer equality tests. Compare only equality tests; no execution times have been supplied.

TargetForward comparisonsReverse comparisonsLower count
14
63
52

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Comparing Implementations for Efficiency Questions: