MR_

POLAND, 2026

Contact
Menu

LAB / ALGORITHMS / DATA

Search Cost

Run linear and binary search on the same sorted data and compare inspected elements.

DEMONSTRATION / EXECUTED ALGORITHM

Operation count0119Linear119Binary7
Target value
118
Linear search
119 comparisons
Binary search
7 comparisons

Both algorithms run over the same sorted integer array. The chart counts inspected elements for this lookup. Sorting cost, wall time and cache effects are excluded.

Question

How many elements do linear and binary search inspect for the same lookup?

Setup

The dataset contains sorted consecutive integers from zero to the selected size minus one. Target position chooses an existing element. Both algorithms execute in the browser, incrementing a counter for each element inspected.

Interpretation

Binary search narrows its interval at each step. Linear search visits elements in order, so looking for the first value can be cheaper than binary search. The result depends on both the algorithm and the query.

Measurement boundary

These are exact operation counts for this model, not execution-time benchmarks. Data preparation, sorting, storage layout and cache behaviour are outside the experiment. This is not a model of the PostgreSQL query planner.

Methodology & reproducibility

Evidence type
Deterministic model, not a runtime benchmark.
Inputs
The values shown in the controls above. Keep them identical when comparing results.
Hardware & trials
No hardware measurements or repeated timing samples are collected.
Median / p95
Not applicable to calculated outputs. These require a distribution of measured samples.

Use this model to form a hypothesis. To validate it in a project, record the source revision, build configuration, hardware, workload, warm-up and trial count; then compare baseline and changed builds under the same conditions.

← All experiments