Tech Store

Showing suggestions.

Opening the store's index…
↑↓ to move↵ to openesc to close
Tech Store search
Animationv1.0.0~13 KB gzipped

Binary Search Animation

A step-by-step binary search with gliding lo / mid / hi pointers, ready for your lessons, slides and posts

FreeFree
Format

.zip · HTML / CSS / JS · v1.0.0

Free — no account, no email. Always the newest version.

Live preview

Version
Preview width
Zoom

About

Binary search is easiest to understand when you watch it throw half the array away. This animation runs the real binarySearch and lowerBound from the free algorithm page, step by step: lo, mid and hi glide over a row of sorted boxes, every arr[mid] vs target is spelled out, the half that can't hold the answer dims and sinks, and the line of code that is running lights up beside it. When the target is there, its box glows and bursts into sparks. When it isn't, a glowing seam shows exactly where it would be inserted.

  • Two functions, one switch: the closed range [lo, hi] of binarySearch and the half-open [lo, hi) of lowerBound
  • A step counter against the ⌈log₂(n + 1)⌉ worst case, and a meter that shows 15 → 7 → 3 → 1
  • Click a box or type any number to search for it; seeded random arrays, or your own values with duplicates
  • A full player with a scrubber and 0.5×–4× speed, built to look good on a slide or in a recording
  • Every colour, radius, font and timing is a CSS custom property; light and dark follow your page
  • Nothing to install: one CSS file and one script, or one React component

Features · 9

  • Animates binarySearch and lowerBound exactly as the free algorithm page writes them, with a switch between the two
  • lo, mid and hi glide over the boxes; the half that can't hold the target dims and sinks away
  • Every comparison spelled out (arr[mid] vs target), with a caption in plain words and the running line lit in the code
  • Found: the box glows and bursts into sparks. Not found: a glowing seam shows where the value would be inserted
  • Step counter against the ⌈log₂(n + 1)⌉ worst case, and a meter of the search space halving
  • Player: play, pause, step back and forward, reset, scrub, 0.5×–4× speed, optional loop
  • Pick the target by clicking a box or typing any number; change the size, roll a new seeded array or bring your own values
  • Plain HTML/CSS/JS and React (Next.js ready) builds, light and dark
  • Zero dependencies, about 13 KB gzipped (script and CSS together)

How to use it

Link the stylesheet and the script once, then add an empty element with data-binary-search-animation wherever you want a player:

HTML
<link rel="stylesheet" href="binary-search-animation.css" />
<script src="binary-search-animation.js" defer></script>

<div class="binary-search-animation" data-binary-search-animation></div>

<div
  class="binary-search-animation"
  data-binary-search-animation
  data-binary-search-animation-mode="lower-bound"
  data-binary-search-animation-values="2 2 2 3 3 5 5"
  data-binary-search-animation-target="3"
></div>

Options as data attributes, all starting with data-binary-search-animation-:

Attribute Default What it does
-mode binary-search binary-search or lower-bound
-values random Your own numbers, separated by spaces or commas (sorted for you)
-target picked from the array The value to search for
-size 15 How many values a random array has (1–40)
-seed 7 Which random array: the same seed always gives the same one
-speed 1 0.25 to 4
-autoplay true Plays on its own once loaded (never with reduced motion)
-loop false Starts again after a pause on the result
-code true false hides the code panel
-inputs true false hides the row of inputs (function, target, size, new array)

Elements added after the page loads: BinarySearchAnimation.init(container); it returns a function that undoes it. For full control, BinarySearchAnimation.createBinarySearchAnimation(element, options) returns a handle with setTarget, setMode, setValues, shuffle, player (play, pause, seek…) and destroy.

Ask about this product

Not sure it fits your project? Ask — the answer comes from this page.

Answers are written by AI from this page and can be wrong. The page itself is what counts.

Changelog

  1. 1.0.0First releaseLatest

    Plain HTML/CSS/JS and React builds of a step-by-step binarySearch and lowerBound animation with gliding lo / mid / hi pointers, live code, a step counter, player controls, light and dark.

  2. Fixes and new features land behind the same download, which always serves the latest version.