Linear Search vs Binary Search Comparison
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 vs timeâcomplexity distinction.
2. Mathematical Elements & Formulas
- Display the two complexity formulas (with opaque background):
- Linear Search:
- Binary Search:
- At the end, show a simple ratio: .
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.
Créé par
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.
Date de création
Feb 11, 2026, 02:00 PM
Durée
0:27
Tags
search-algorithmsalgorithm-analysiscomplexity