Skip to content

Repository files navigation

🌳 Binary Search Tree Visualizer

An interactive web app that animates the core Binary Search Tree (BST) operations β€” Insert, Search, and Delete β€” step by step, so you can see exactly how the algorithm walks the tree, compares nodes, and restructures itself. Each operation is paired with reference implementations in five programming languages.

Built with React 19, Vite, Tailwind CSS, and GSAP animations.

A Data Structures & Algorithms course project.


✨ Features

  • Step-by-step animation of the three fundamental BST operations:
    • Insert β€” recursive descent to find the correct leaf position
    • Search β€” O(log n) average-case lookup with a highlighted comparison path
    • Delete β€” handles all three cases (leaf, one child, two children) using the in-order successor
  • Playback controls β€” play, pause, step forward/back, skip to end, and reset
  • Preset trees to start from β€” Simple, Basic, Balanced, and Right-Skewed (worst case), plus an Empty tree to build from scratch
  • Color-coded node states β€” comparing, visited path, found, target, newly inserted, removed, and "reached NULL"
  • Reference code for every operation in C, C++, Java, Python, and JavaScript, with a one-click copy button
  • Light / dark mode and a responsive, animated UI
  • Fullscreen mode for presentations and lectures

🧠 How BST operations work

Operation Idea Average Worst
Search Compare with the current node; go left if smaller, right if larger. O(log n) O(n)
Insert Search for the value's position, then attach it as a new leaf. O(log n) O(n)
Delete Remove the node; if it has two children, replace it with its in-order successor. O(log n) O(n)

The worst case (O(n)) happens on a skewed tree β€” try the "Skewed (right)" preset to watch search degrade into a linear scan.


πŸ› οΈ Tech Stack


πŸš€ Getting Started

Prerequisites

  • Node.js 18 or newer
  • npm (comes with Node.js)

Installation

# Clone the repository
git clone https://github.com/CODEIFIE/bst-visualizer.git
cd bst-visualizer

# Install dependencies
npm install

# Start the development server
npm run dev

Then open the URL shown in the terminal (usually http://localhost:5173).

Available scripts

Command Description
npm run dev Start the development server with hot reload
npm run build Build the app for production (output in dist/)
npm run preview Preview the production build locally
npm run lint Run ESLint

πŸ“– Usage

  1. Pick a starting tree from the presets (or start with an empty tree).
  2. Choose an operation β€” Insert, Search, or Delete β€” and enter a value.
  3. Run it and use the playback controls to step through the animation at your own pace.
  4. Read the message panel to follow what the algorithm is doing at each step.
  5. Switch languages in the code panel to see the same operation implemented in C, C++, Java, Python, or JavaScript.

πŸ“ Project Structure

bst-visualizer/
β”œβ”€β”€ public/                 # Static assets (icons, favicon)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ BSTVisualizer.jsx   # Main component: BST logic, step generators & animation
β”‚   β”œβ”€β”€ App.jsx             # Root app component
β”‚   β”œβ”€β”€ main.jsx            # Entry point
β”‚   β”œβ”€β”€ components/         # Reusable UI & animation components
β”‚   β”œβ”€β”€ lib/                # Utility helpers
β”‚   └── index.css           # Global styles
β”œβ”€β”€ index.html
β”œβ”€β”€ vite.config.js
└── package.json

The BST algorithms live in src/BSTVisualizer.jsx. Each operation is implemented as a step generator (generateInsertSteps, generateSearchSteps, generateDeleteSteps) that records a snapshot of the tree at every stage, which the UI then plays back frame by frame.


πŸ‘₯ Team

Name Roll Number
Muhammad Afnan G1F24UBSCS070
Khurram Malik G1F24UBSCS079
Fraz Ali Ghumman G1F24UBSCS091

πŸ“„ License

This project is released under the MIT License.

About

Interactive Binary Search Tree Visualizer β€” animate Insert, Search & Delete step by step, with reference code in C, C++, Java, Python & JavaScript.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages