Tiem Cong Nghe

Showing suggestions.

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

Kruskal Animation

A glowing graph where the cheapest network builds itself: Kruskal's minimum spanning tree with a sorted edge list and union-find colours, for lessons and slides

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

Kruskal's algorithm is easiest to understand when you watch the cheapest network build itself. This animation runs a real kruskal and find, step by step: the edges sort themselves lightest first, then each one is picked up and tried. If its two ends are already in the same component it would close a cycle and is refused, struck through and dashed. Otherwise it is taken, the smaller tree goes under the bigger one, and the two colours become one. The parent and size arrays sit under the graph and change in step, the line of code that is running lights up beside it, and a running total climbs until a single gold tree connects everything.

  • The listing's own logic: a stable sort, union by size, an early stop once the tree is full, checked against a differently written Kruskal, Prim's algorithm and a brute-force search on seeded random graphs
  • A sorted edge list you can read: chips glide into place, then show taken, refused or never reached
  • Union-find as colour: one colour per component, the root's number under every vertex, and a table of parent and size
  • A running total weight and a count of tree edges out of n − 1
  • Four seeded graphs (a fibre network, a cycle trap, a tie-break and a forest of islands), or your own edges typed in
  • 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 · 12

  • Animates kruskal and its find exactly as the panel lists them: a stable sort by weight, find on both ends of every edge, a refusal when the roots match, otherwise the smaller tree goes under the bigger (union by size); the listing is run as code in the tests and checked against the animation
  • The edges sit in a grid that sorts itself: chips glide into lightest-first order, then each one is picked up, tried (both ends and their roots light up), and taken, struck through and dashed as a cycle, or never reached once the tree is complete
  • Union-find components as colour: every vertex wears its tree's colour with its root's number underneath, and when two trees merge the smaller one flashes and takes the bigger one's colour
  • A running total that ticks up with every edge taken, the tree edges counted out of n − 1, and a finished tree that glows gold in a wave across the nodes
  • A parent and size table under the graph, in step with every frame, so the disjoint-set arrays are visible, not just implied
  • Edge cases shown honestly: equal weights are taken in written order, a graph in pieces ends as a spanning forest with one tree per island, and a complete tree stops early with the leftover edges marked
  • Four seeded graphs: a fibre network, a cycle trap of three triangles, a tie-break and a forest of islands, with a New button for fresh weights
  • Type your own graph like 0-1:4; 1-2:3 (up to 12 vertices and 24 edges, weights 0–99, parallel edges allowed)
  • The code panel shows kruskal and find with the lines that are running lit, and the call stack changes while find runs
  • Player: play, pause, step back and forward, reset, scrub, 0.5×–4× speed, optional loop
  • Plain HTML/CSS/JS and React (Next.js ready) builds, light and dark
  • Zero dependencies, about 20 KB gzipped (script and CSS together)

How to use it

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

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

<div class="kruskal-animation" data-kruskal-animation></div>

<div
  class="kruskal-animation"
  data-kruskal-animation
  data-kruskal-animation-scenario="cycles"
  data-kruskal-animation-seed="3"
></div>

<div
  class="kruskal-animation"
  data-kruskal-animation
  data-kruskal-animation-edges="0-1:4; 0-2:1; 2-1:2; 1-3:1; 2-3:5; 3-4:3"
></div>

Options as data attributes, all starting with data-kruskal-animation-:

Attribute Default What it does
-scenario network network, cycles, ties or islands: the graph to run
-edges the preset's Your own graph: a-b:w for an edge between a and b that costs w, separated by ;, , or new lines (up to 24, weights 0–99, vertices 0–11; the weight defaults to 1)
-vertices as many as the edges name How many vertices your own graph has (2–12); the ones no edge names stay alone
-seed 21 Which weights the preset builds: the same seed always gives the same graph
-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 answer
-code true false hides the code panel
-inputs true false hides the rows of inputs (graph, edges)

Elements added after the page loads: KruskalAnimation.init(container); it returns a function that undoes it. For full control, KruskalAnimation.createKruskalAnimation(element, options) returns a handle with setScenario, setEdges(text) (it returns false and says why on the page when the edges cannot be read), setVertices, shuffle, player (play, pause, seek…), trace() and destroy.

The algorithm itself is pure and lives in core/trace.ts: traceKruskal(n, edges) takes the vertex count and a list of [u, v, weight] triples and returns every frame (state, caption and the lines running), the edge ids of the tree in the order they were taken, and its total weight.

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 Kruskal minimum spanning tree animation: the edges sort themselves lightest first, each one is tried, taken or refused as a cycle, union-find components blend into one colour as islands merge, a running total climbs and the finished tree glows, a live parent / size table, four seeded graphs (one with ties, one in pieces) or your own edges, player controls, light and dark.

  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.

  • AnimationGraphs

    Topological Sort Animation

    A glowing dependency graph that peels itself in order: Kahn's algorithm with live in-degree badges, a visible FIFO queue and the order filling up

    Free
  • AnimationGraphs

    Graph Traversal Animation

    Queue or stack, watch the search choose: BFS and DFS on a glowing graph, side by side, ready for your lessons, slides and posts

    Free