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.