Tiem Cong Nghe

Showing suggestions.

Opening the store's index…
↑↓ to move↵ to openesc to close
Tiem Cong Nghe search
Animationv1.0.0~19 KB gzipped

Merge Sort Animation

Merge sort, step by step: halves splitting level by level, then two sorted runs merging through one buffer

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

Merge sort is easy to say and hard to see: cut the array in half until pieces are one value, then merge sorted pieces back up. This player shows both halves of that. The array splits level by level while a recursion tree grows under it, and every merge lifts its two halves onto a buffer shelf, then drops the smaller front value back into the array while the pointers i, j and k walk along. Finished stretches turn green, and the call stack beside it shows it never goes deeper than ⌈log₂ n⌉.

  • Exactly the listing on the Merge Sort page, and its code lights up line by line as it runs
  • Captions in plain words ("buffer[i] = 3 <= buffer[j] = 3? Yes, they are equal, and the left one goes first") for every step
  • Random, sorted, reversed, nearly sorted or many-duplicates input from a seed, or your own numbers
  • Equal values carry a letter, so you can watch the sort stay stable
  • Play, step, scrub and change speed with the mouse or the keyboard; it loops for a slide or a video
  • Every colour, radius and timing is a CSS custom property; light and dark follow your page
  • Nothing to install: one CSS file and one small script, or one React component

Features · 11

  • Follows the algorithm page's listing exactly: top-down halves, one buffer made once, a tie going to the left half
  • The array splits into halves level by level, with a recursion tree under it that fills in as the calls are made and turns green as they return
  • A merge lifts both halves onto a buffer shelf, then drops the smaller front into place with the i, j and k pointers walking along
  • The listing's own code with the running line lit, and a call stack with a depth gauge against ⌈log₂ n⌉
  • A caption in plain words for every step, plus comparisons, writes and stack depth
  • Random, sorted, reversed, nearly sorted or many-duplicates presets from a seed you can replay, or type your own numbers
  • Equal values carry a letter (3a, 3b), so you can watch the sort stay stable
  • Play, pause, step, scrub and 0.5×–4× speed; a small celebration when the array is sorted
  • Dark aurora look that also works light; fits a phone, a blog post or a 16:9 slide
  • Plain HTML/CSS/JS and React (Next.js ready) builds
  • Zero dependencies, about 19 KB gzipped (script and styles together)

How to use it

Link the stylesheet and the script once, then mark an empty element with data-merge-sort-animation. It builds the whole player inside it:

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

<div data-merge-sort-animation data-merge-sort-size="12" data-merge-sort-loop></div>

<!-- your own values, without the extra panels: good for a slide -->
<div
  data-merge-sort-animation
  data-merge-sort-values="8, 3, 5, 3, 9, 1"
  data-merge-sort-inputs="false"
  data-merge-sort-panels="false"
></div>

Options as data attributes (a boolean is on when present, off when it says "false"):

Attribute Default What it does
data-merge-sort-values — Your numbers, separated by commas or spaces (48 at most); replaces the generated array
data-merge-sort-size 12 Bars in a generated array, 2 to 48
data-merge-sort-scenario random random, sorted, reversed, nearly or duplicates
data-merge-sort-seed 7 Which generated array: the same seed always draws the same one
data-merge-sort-speed 1 0.25 to 4
data-merge-sort-autoplay on Starts playing on load (never with prefers-reduced-motion)
data-merge-sort-loop off Starts over after the last step
data-merge-sort-inputs on The size and preset pickers, "New input" and the field for your own numbers
data-merge-sort-panels on The code and call-stack panels

Players added after the page loads: MergeSortAnimation.init(container) — it returns a function that undoes it. To drive one from your own code (a slide clicker, say), build it yourself:

JavaScript
const player = MergeSortAnimation.create(element, { values: [5, 1, 4, 2, 3], autoplay: false });
player.stepForward();
player.seek(20);
player.setValues([9, 8, 7]);
player.destroy(); // the element is given back as it was

The handle also has play, pause, stepBack, reset and frameCount.

With focus anywhere in the player, Space plays or pauses, ← / → step and Home goes back to the start. In the numbers field the keys stay the field's own; Enter sorts what you typed.

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 merge sort player (top-down halves, one shared buffer, ties going left so the sort stays stable) with a recursion tree, the listing's code, call stack, counters, seeded presets, your own numbers, keyboard and reduced-motion support.

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

Reviews

No reviews yet

Used it? Be the first to say how it went.

Write a review

How did it work for you? Reviews appear once we have read them.

Your rating
Never shown. Only used if we need to reach you about your review.
0 / 2000

Your name and review are shown on this page; your email is not. See the terms.

  • AnimationSorting

    Insertion Sort Animation

    A card lifted out of the row, bigger bars sliding right underneath, a gap that travels left: insertion sort as shifting, never swapping

    Free
  • AnimationSorting

    Heap Sort Animation

    The array and the binary tree it stands for, side by side: every sink moves both at once, the heap shrinks and the sorted tail locks in

    Free
  • AnimationSorting

    Bubble Sort Animation

    The interactive version of the short video: bars that cross when they swap, a sorted tail that grows, and the early exit

    Free