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

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

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

Breadth-first and depth-first search are the same code with one different container, and that one change is easiest to understand when you watch it. This animation runs the real bfs and dfs from the free Graph Traversal page, step by step, on a glowing node-link graph: BFS takes the oldest vertex from a queue and spreads out in rings, DFS takes the newest from a stack and dives along a trail before it backs up. The queue (with its head) or the stack (with its top) is drawn live under the graph, the line of code that is running lights up beside it, and a strip of numbered badges fills in with the order of the visit.

Press Compare and both searches run side by side on the same graph, one timeline, so you can point at the exact step where they part ways. The two moments the page spends the most words on are impossible to miss: BFS marking a vertex the instant it is queued, and DFS throwing away a stale entry that was pushed twice.

  • Exactly the listing's logic: BFS marks on push, DFS pushes neighbours last to first, marks on pop and skips stale entries
  • Compare mode with one shared timeline, or BFS and DFS on their own
  • Six preset graphs, including the page's A–F graph, islands the search cannot cross and a cycle that makes DFS skip a stale entry, or type your own edges and pick the start vertex
  • Counters for visited, pushes, stale skips and the biggest the queue or stack got
  • 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 · 14

  • Animates bfs and dfs exactly as the free algorithm page writes them: BFS with a queue and a head index that marks a vertex when it is pushed, DFS with an explicit stack that pushes neighbours last to first, marks on pop and skips stale entries
  • A glowing node-link graph: every vertex takes a colour from its depth in the traversal tree, so BFS fills in as rings and DFS changes hue as it dives; tree edges light up from parent to child and the edges the tree does not need are dimmed
  • A live queue with its head pointer, or a stack with its top: every entry shows who put it there, and a stale copy is struck through the moment its vertex is marked, then thrown away on a step of its own
  • The two moments the page is about get their own colour on the listing: the BFS line visited[v] = true lights mint, the DFS line if (visited[u]) continue lights amber when it fires
  • A glowing trail from the start to the vertex being processed, which flows towards it and shortens when DFS backs up
  • A visit-order strip that fills with numbered badges, grouped by level for BFS and by branch for DFS
  • Compare mode: BFS and DFS side by side on the same graph, on one timeline, so step 20 is the same step in both
  • Six preset graphs (the page's A–F graph, a binary tree, a grid, islands, a cycle, a seeded random graph) or your own edges like 0-1; 0-2; 1-3, with 2–16 vertices and any start vertex
  • Vertices the search cannot reach are dimmed on the last frame and the caption names them
  • Counters for visited, pushes, stale skips and the most the queue or stack held at once
  • The code panel shows the listing's own lines for the search that is running, with the lines of the current step lit
  • 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-graph-traversal-animation wherever you want a player:

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

<div class="graph-traversal-animation" data-graph-traversal-animation></div>

<div
  class="graph-traversal-animation"
  data-graph-traversal-animation
  data-graph-traversal-animation-preset="tree"
  data-graph-traversal-animation-mode="bfs"
></div>

<div
  class="graph-traversal-animation"
  data-graph-traversal-animation
  data-graph-traversal-animation-edges="0-1; 0-2; 1-3; 2-3; 3-4; 2-5"
  data-graph-traversal-animation-start="0"
></div>

Options as data attributes, all starting with data-graph-traversal-animation-:

Attribute Default What it does
-preset page page, tree, grid, islands, cycle or random: the graph to search
-edges the preset's Your own graph: edges like 0-1 or 0 1, separated by ;, , or new lines (up to 40, vertices 0–15). The order sets each vertex's neighbour list, which is the order a search tries them in
-vertices just enough How many vertices your own graph has (2–16, never fewer than the edges name); the extra ones stand alone
-start the preset's The vertex both searches start at
-mode compare bfs, dfs, or compare to run both side by side on one timeline
-seed 7 Which graph the random preset draws: 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 last frame
-code true false hides the code panels
-inputs true false hides the rows of inputs (preset, mode, edges, vertices, start)

Elements added after the page loads: GraphTraversalAnimation.init(container); it returns a function that undoes it. For full control, GraphTraversalAnimation.createGraphTraversalAnimation(element, options) returns a handle with setPreset, setEdges(text) (it returns false and says why on the page when the edges cannot be read), setVertices, setStart, setMode, shuffle, player (play, pause, seek…), traces() (one per search on show, every frame included) 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 BFS and DFS animation: a glowing node-link graph, a live queue with its head or a stack with its stale entries struck through, a numbered visit-order strip, side-by-side compare mode, six preset graphs or your own edges, live code, counters, 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

    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

    Free
  • 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