Algorithm & data structure visualizer
Produces an interactive, step-through animation (a single self-contained HTML file by default, or via the host runtime's interactive widget tool if one exists) for any sorting algorithm, searching algorithm, or core data structure operation. The output is always a live widget with Play / Next step / Reset controls — never a static image and never a set of pre-rendered "frames" the user has to flip through manually.
Workflow
Identify the category the request falls into:
- Sorting → read
references/sorting.md - Searching → read
references/searching.md - Data structure (stack, queue, linked list, tree, graph) → read
references/data-structures.md - If ambiguous (e.g. "show me heaps"), pick the most common interpretation and proceed — don't stall on a clarifying question for a well-known topic.
- Sorting → read
Pick the audience level. Default to kid-friendly unless the request signals otherwise:
- Kid-friendly (default): plain-language status line ("Comparing 5 and 3"), no jargon like "O(n log n)", encouraging tone, bigger fonts/bars, simple counters (comparisons, swaps).
- Technical: use when the user mentions complexity/Big-O, says "for my CS class / interview prep / technical audience", asks for pseudocode alongside, or has previously been talking about the topic in technical terms. In this mode it's fine to label time/space complexity, use precise terminology (pivot, node, dequeue), and show more state (e.g. the call stack for recursive algorithms).
- If genuinely unsure and it meaningfully changes the output, ask one quick question — otherwise default to kid-friendly, since that's the more common use case for this skill.
Precompute the action list before rendering anything. This is the core pattern (see the bubble sort example in
references/sorting.md): write plain JS that runs the algorithm once, pushing a structured action object at every meaningful step (compare, swap, visit, push, pop, insert, rotate, etc.) into an array. The widget then just steps through that array on Play/Next — it never re-runs algorithm logic live. This keeps timing deterministic and makes "Next step" trivial to implement.Build the widget. First read
references/design.mdand answer its 开工五问 — pick the topic's 生活母题 (the life analogy: sorting = kids lining up by height, Hanoi = stacking plates/rings, merge sort = merging two sorted lines, binary search = the half-guessing game). The 母题 seeds the layout, the status copy, and the one signature detail. Then use the standard control layout (reuse this shape every time so the pattern feels familiar across topics):- Top row:
Next stepbutton,Play/Pausetoggle button, a reset button (label it for what it regenerates — "New numbers", "New list", "New tree"), and a speed slider on the right. - A single-line status text describing the current action in the chosen audience level's language.
- The stage: the visual itself (bars, boxes, nodes, arrows) — animate position/color changes with CSS transitions, don't hard-cut. Keep DOM elements persistent and toggle classes; never rebuild
stage.innerHTMLevery frame (it kills transitions and you lose the swap animation). - A small counters row relevant to the structure (comparisons/swaps for sorting, comparisons for searching, operation counts for data structures) — only real metrics, no decorative stats.
- Apply
references/design.md— warm cohesive palette (paper background, one cool accent), Fredoka rounded display type for numbers, bars with craft (ground line + soft contact shadow), restrained emoji, anti-slop, and exactly one signature detail done at 120% (spring swap / settle bounce / done confetti / recursion-stack浮窗 / divide-tree展开). If the runtime provides avisualizewidget tool you may host the widget there, but this design system governs either way. - Use the semantic color roles from
design.mdconsistently:--rest(resting),--focus(comparing/visiting),--move(about to swap/move),--done(finalized/found),--star(current min / pivot / special pointer).
- Top row:
Write the accompanying explanation as normal response text outside the widget — a short, concrete analogy suited to the audience level (see the bubble-sort "kids lined up by height" example), plus 2-4 bullet tips for how to use the animation to teach the concept (e.g. "have them predict before clicking next"). Don't repeat the visual in prose.
Offer natural next steps — related algorithms/structures that pair well for comparison (e.g. bubble sort → selection/insertion sort; binary search → linear search; stack → queue), so the user can build an intuition for the differences.
Notes
- Every animation should be genuinely interactive (Play/Pause/Next/Reset), not a fixed gif-like loop — that's what makes this better than a canned animation and what justifies using this skill over a quick illustration.
- Default output is a single self-contained HTML file (inline CSS/JS, font via CDN, mobile-first, follows system dark mode). Don't assume a
visualizewidget tool exists —references/design.mdis the design truth source either way. - Hold the anti-slop line (
design.md§7): warm paper background (not cold gray/blue), no purple gradients, restrained emoji (kid context allows a little, not one on every button), bars with craft (ground line + soft shadow). Kid-friendly ≠ neon rainbow. The old output looked generic precisely because it had no design system of its own — design.md fixes that. - Keep arrays/structures small (6-10 elements) so bars/nodes fit comfortably and steps are easy to follow.
- Reuse the exact action-list + step-through architecture across all topics; only the action types and the render function change per topic. This consistency is what makes the skill fast to apply to a new topic on request.
- If the user asks for a whole family at once ("show me all the sorting algorithms"), build one topic at a time, each as its own widget with a bit of prose in between — don't cram multiple structures into one widget.




