Tiem Cong Nghe

Showing suggestions.

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

Trie Animation

A glowing tree that grows letter by letter, with shared prefixes, snapping lookups and autocomplete: a Trie 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

A trie is easiest to understand when you watch it grow. This animation runs the real insert, search, startsWith, countWithPrefix, delete, autocomplete, nodeCount and size from the free algorithm page, step by step: every letter is a glowing node in a tree that grows to the right like a line of text, words that start the same way share their first nodes, and a star marks where a word ends. A cursor walks the path of each call, a lookup snaps off at the letter that is missing, a prefix query lights up the whole subtree, and delete cuts a branch the moment nothing lives below it. The letters sit on a tape above the tree, the 26 child slots of the node under the cursor sit below it, the line of code that is running lights up beside it, and a pair of bars sets the letters you typed against the nodes that were built.

  • Every public method of the listing, line for line, with the private helpers (#find, #childOrCreate, #collect, #countNodes) shown when they run
  • Shared prefixes you can see: nodes an insert walks over are marked as reused, only new letters build nodes, and a badge on every node counts the words going through it
  • Lookups that snap off where a letter is missing, prefix queries that light the subtree and list its words, autocomplete that fills its pills a to z and stops at the limit
  • delete that subtracts along the path, cuts dead branches and only clears the star of a word that starts another
  • Three seeded scenarios, autocomplete, shared prefixes and prune a branch, or your own operations typed in; every operation in the script is a button that jumps to it
  • Counters for nodes created, visited and shared, and the letters typed against the nodes built
  • 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 every public method of the free page's Trie, exactly as the listing writes it: insert, search, startsWith, countWithPrefix, delete, autocomplete, nodeCount and size
  • A tree that grows to the right like a line of text: insert builds a node for each new letter and walks over the ones that already exist, so a shared prefix is visibly reused instead of built twice
  • A star marks the node where a word ends, and a badge on every node shows its passCount, the number of words going through it
  • A cursor walks the path of every call, with the listing's own variables (node, child, start) gliding along as chips and the letters on a tape above the tree
  • A failed lookup snaps off where the letter is missing: the node shakes, the tape marks the letter and the slot strip shows the empty slot
  • A prefix query lights the whole subtree and lists the words under it; autocomplete collects them a to z, one pill at a time, and stops the moment it reaches the limit
  • delete subtracts along the path and cuts a branch the instant its count reaches zero, while a word that is the start of another one only loses its star
  • The 26 child slots of the node under the cursor, so you can see the array behind the tree and why a traversal is already in alphabetical order
  • A script of operations you can press to jump to: three seeded scenarios (autocomplete, shared prefixes, prune a branch), or type your own like insert car; insert card; auto ca 3
  • Counters for nodes created, visited and shared, and two bars that set the letters typed against the nodes built: the gap is what sharing saved
  • The code panel shows the method that is running, public or private, with the call stack above it and the lines of the 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 24 KB gzipped (script and CSS together)

How to use it

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

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

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

<div
  class="trie-animation"
  data-trie-animation
  data-trie-animation-scenario="prune"
  data-trie-animation-speed="2"
></div>

<div
  class="trie-animation"
  data-trie-animation
  data-trie-animation-operations="insert car; insert card; insert dog; count ca; auto ca 3"
></div>

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

Attribute Default What it does
-scenario autocomplete autocomplete, prefixes or prune: the list of operations to run
-operations the scenario's Your own list, separated by ;, , or new lines (up to 24, and up to 80 inserted letters): insert w, search w, starts p, count p, delete w, auto p limit, nodes and size. Words and prefixes are lowercase a–z, up to 12 letters; a lone - is the empty prefix
-seed 7 Which list the scenario builds: 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 summary
-code true false hides the code panel
-inputs true false hides the rows of inputs (scenario and operations)

The operations are the methods of the free page's Trie: starts is startsWith, count is countWithPrefix, auto is autocomplete and nodes is nodeCount. The box also reads the method names themselves, in any case.

Elements added after the page loads: TrieAnimation.init(container); it returns a function that undoes it. For full control, TrieAnimation.createTrieAnimation(element, options) returns a handle with setScenario, setOperations(text) (it returns false and says why on the page when the list cannot be read), shuffle, player (play, pause, seek…), trace() 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 Trie animation: a tree that grows letter by letter with shared prefixes reused, end-of-word stars, a cursor that walks every insert, search, prefix count, delete and autocomplete, a lookup that snaps off at the missing letter, branches that are cut when their count hits zero, three seeded scenarios or your own script, 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.

  • AnimationData structures

    LRU Cache Animation

    A hash map beside a doubly linked list: hits fly to the front, the oldest node falls away. The O(1) LRU cache, ready for your lessons, slides and posts

    Free
  • AnimationData structures

    Union-Find Animation

    A glowing forest where groups merge and paths flatten: Union-Find with union by size and path compression, ready for your lessons, slides and posts

    Free