Skip to content

dev48v/binary-search-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🌳 Binary Search Tree Visualizer — insert, search, delete and traverse, animated

An interactive, single-file binary search tree that runs entirely in your browser — no backend, no build step.

▶ Live: https://dev48v.github.io/binary-search-tree/

A BST keeps one invariant at every node: everything on the left is smaller, everything on the right is larger. That single rule is what makes search, insert, and delete run in O(height). This shows the rule at work.

What it shows

  • Insert — a new value walks down from the root, going left or right by comparison until it finds an empty spot. Watch the path light up.
  • Search — same walk: compare, turn left or right, never scan the whole tree. The comparison count is the depth, not the size.
  • Delete — the interesting one. Three cases: a leaf just goes; a node with one child is replaced by that child; a node with two children is replaced by its in-order successor (the smallest value in its right subtree) — the one swap that preserves the ordering.
  • Four traversals, animated in visit order:
    • in-order (Left, Node, Right) → comes out sorted every time
    • pre-order (Node, Left, Right) → used to copy/serialize a tree
    • post-order (Left, Right, Node) → used to delete/free a tree bottom-up
    • level-order (breadth-first) → row by row

Live stats show node count, height, min, and max.

Try it

  1. random tree, then in-order — always sorted ascending. That's a one-liner sort.
  2. search a value and count the comparisons — it's the depth, not the size.
  3. delete a node with two children and watch the in-order successor take its place.
  4. Insert values in sorted order (1, 2, 3, …) and watch the tree degenerate into a linked list — height = n. That worst case is exactly why balanced trees (AVL, red-black) exist.

Insert/search/delete logic, the in-order-successor delete, and all four traversals are the real algorithms; the animation replays the node visits.

Run locally

It's one file. Open index.html, or:

python -m http.server 8000   # then visit http://localhost:8000

License

MIT © 2026 dev48vdev48v.infy.uk

About

Interactive binary search tree — insert, search and delete values and watch them walk left/right by comparison, plus animated in-order, pre-order, post-order and level-order traversals (in-order comes out sorted). Real BST algorithms incl. in-order-successor delete. Runs in your browser.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages