Linear Search vs Binary Search Comparison

Loading...

Loading video...

Pro
0:00 / 0:00

Animation Specification: Linear Search vs Binary Search

1. Animation Description & Purpose

  • Visually compare the step‑by‑step operation of a linear search and a binary search on the same sorted array. The goal is to illustrate why binary search requires far fewer comparisons, reinforcing the O(n)O(n) vs O(logn)O(\log n) time‑complexity distinction.

2. Mathematical Elements & Formulas

  • Display the two complexity formulas (with opaque background):
    • Linear Search: Tlin(n)=nT_{lin}(n) = n
    • Binary Search: Tbin(n)=log2nT_{bin}(n) = \log_2 n
  • At the end, show a simple ratio: Tlin(16)Tbin(16)=164=4\frac{T_{lin}(16)}{T_{bin}(16)} = \frac{16}{4}=4.

3. Visual Elements

  • Array Representation: A horizontal row of 16 square cells, each labeled with its index (0‑15) and a distinct integer value in ascending order (e.g., 3, 7, 12, …). Cells have a light gray fill and thin black border.
  • Search Target: A highlighted target value (e.g., 42) that is present at index 11. The target value is displayed above the array with an opaque background.
  • Linear Search Highlight:
    • Color: Warm orange (RGB ~255,140,0).
    • A thick orange border sweeps left‑to‑right, covering one cell per frame.
    • A small orange counter (opaque background) increments with each comparison.
  • Binary Search Highlight:
    • Color: Cool blue (RGB ~30,144,255).
    • A thick blue border appears around the current middle cell, then jumps to the appropriate half.
    • A blue counter (opaque background) increments with each comparison.
  • Comparison Summary Panel (bottom of the screen): Two side‑by‑side boxes showing the current count for each algorithm, each with an opaque background.

4. Animation Timing & Transitions

Segment Duration Details
Intro (title & array appear) 3 s Fade‑in title "Linear Search vs Binary Search" (opaque background). Array slides in from left.
Linear Search Phase 6 s Each cell highlighted for 0.35 s; counter updates. Total 16 steps → 5.6 s, plus brief pause after finding target.
Transition (wipe) 1 s Quick wipe to reset array colors while keeping target highlighted.
Binary Search Phase 5 s Highlight middle cell (index 7) for 0.8 s, then move to right half (index 11) for 0.8 s, then final match (index 11) for 0.8 s. Counter updates each step (3 comparisons).
Summary & Complexity 4 s Show both formulas, the ratio, and a final side‑by‑side bar chart comparing 16 vs 3 comparisons (bars with opaque backgrounds).
Fade‑out 1 s All objects fade out together.
  • Total runtime ≈ 20 seconds, well under the 30‑second limit.

5. Camera Angles & Perspectives

  • Fixed orthographic camera, centered on the array. Slight slow zoom‑in (1.1×) during the binary search phase to emphasize the halving process.
  • No rotation or pan; all motion is confined to object transforms.

6. Additional Details

  • All text (titles, formulas, counters) uses a sans‑serif font, white text on a semi‑transparent dark rectangle (opacity 0.7) to guarantee readability.
  • The background of the scene is a dark navy gradient to make orange and blue highlights pop.
  • No extra explanatory text beyond the formulas and counters; the visual progression conveys the comparison.

Created By

Varsha WanjariVarsha Wanjari

Description

An animated comparison of linear and binary search on a sorted array of sixteen elements. The linear search highlight sweeps each cell in orange while a counter increments, then a blue highlight performs binary search by repeatedly halving the interval. Formulas for linear (n) and binary (log base 2 of n) time are shown, followed by a ratio and bar chart illustrating the fewer comparisons.

Created At

Feb 11, 2026, 02:00 PM

Duration

0:27

Tags

search-algorithmsalgorithm-analysiscomplexity

Status

Completed
AI Model
GPT-OSS-120b

Fork