An interactive, visual explorer for binary and n-ary tree traversal algorithms, designed for A-Level Computer Science students and anyone learning tree traversals for the first time.
- Three traversal algorithms — Pre-order (Root, L, R), In-order (L, Root, R), Post-order (L, R, Root)
- Animated step-by-step playback with adjustable speed
- Manual stepping — click once to advance one step, hold to auto-step at the current speed
- Configurable tree — set min/max depth and min/max children per node; regenerate instantly with the ↻ button
- Live code panel — syntax-highlighted pseudocode in JavaScript, Python, or C#, with the active line highlighted as the traversal runs
- Call stack panel — real-time call stack visualisation showing recursive calls and their return values
- Sequence bar — the visited node sequence builds up as the traversal progresses
- Dark / light theme toggle
- Resizable panels — drag the dividers to customise the layout; hide the Code or Call Stack panels independently
You can customise the initial state of the application using URL parameters. This is useful for creating shareable links with specific configurations.
lang— Set the initial language (e.g.,?lang=python).categories— Filter the language dropdown to show only languages matching the specified categories (comma-separated, e.g.,?categories=AQA,OCR).settings— Toggle the visibility of the settings (left) panel (trueorfalse).code— Toggle the visibility of the code panel (trueorfalse).callStack— Toggle the visibility of the call stack panel (trueorfalse).sequence— Toggle the visibility of the sequence bar (trueorfalse).traceLine— Toggle the code line tracing (trueorfalse).focus— Toggle focus mode, hiding boilerplate code (trueorfalse).
No build step is required — this is a plain HTML/CSS/JS application.
git clone https://github.com/DevDecoder/tree-traversals.git
cd tree-traversals
npx serve .Then open http://localhost:3000 in your browser.
git clone https://github.com/DevDecoder/tree-traversals.git
cd tree-traversals
python3 -m http.server 8080Then open http://localhost:8080.
Install the Live Server extension, open the repo folder, and click Go Live in the status bar.
Note: The app uses ES modules (
type="module"), so it must be served over HTTP — openingindex.htmldirectly as afile://URL will not work.
tree-traversals/
├── index.html # Application shell
├── styles.css # All styling
├── languages/ # Language template specifications (.lang files)
├── docs/ # Documentation
└── src/
├── main.js # Entry point
├── ui.js # UI controller — event handling, panel visibility, animation loop
├── tree.js # Tree data structure and SVG renderer
└── traversal.js # Generator-based traversal algorithms and Animator class
The repository includes a GitHub Actions workflow (.github/workflows/deploy.yml) that automatically deploys the main branch to GitHub Pages on every push.
To enable it for a fork:
- Go to Settings → Pages in your repository.
- Set Source to GitHub Actions.
- Push any change to
main— the workflow will build and deploy automatically.
The live site will be available at https://<your-username>.github.io/<repo-name>/.
We welcome community contributions! The easiest way to get involved is by adding support for new programming languages or pseudocodes.
The application uses a custom, language-agnostic template format (.lang) to build code snippets and logic block highlighting.
- Learn how to add a language: Contributing Guidelines
- Learn how the templating engine works: Language Format Reference