Afterglowscreensavers

Binary Search Tree Builder Screensaver

The Binary Search Tree Builder screensaver grows a real, unbalanced binary search tree live from a stream of random inserts. It is free, runs in your browser, and ESC exits.

Live preview

Binary Search Tree Builder screensaver — A real binary search tree, growing from random inserts.

Press ESC to leave fullscreen. Settings are saved in your browser only.

How the Binary Search Tree Builder screensaver works

The saver generates a real random value and inserts it starting at the root, going left or right at each node exactly the way a real BST insert works.

The new value settles into its correct real position — smaller values end up to the left, larger ones to the right, all the way down.

With no rebalancing, a run of similar values can genuinely make one side of the tree grow much deeper than the other, exactly like a real plain BST.

Once the tree reaches a set size, it holds briefly, then clears and a fresh binary search tree begins growing from empty.

Why order of insertion shapes a search tree

A binary search tree stores values so that each node has at most two children: everything in the left subtree is smaller than the node, and everything in the right subtree is larger. To find a value you start at the root and go left or right at every step, discarding about half of what remains if the tree is reasonably balanced. That makes searching, inserting and deleting take time proportional to the height of the tree.

The height depends on the order in which values arrive. If they come in random order, the expected height is proportional to the logarithm of the number of values, so lookups are fast. If they arrive already sorted, every new value goes to the same side and the tree degenerates into a chain no better than a linked list, with search time proportional to the number of items.

This weakness led to self-balancing variants, such as the AVL tree of Adelson-Velsky and Landis from 1962 and the red-black tree, which rotate nodes after changes to keep the height small. A useful property of the plain tree is that reading it left to right, an in-order traversal, returns the values in sorted order.

A worked example

A long run of steadily increasing random values makes the tree lean hard to the right, growing tall and thin exactly the way a real unbalanced BST degrades toward a linked list.

Settings & tips

Frequently asked questions

Is this a real binary search tree?
Yes — a real, correct BST, with every insert following the real left-smaller, right-larger rule.
Why isn't it balanced?
Plain BSTs really do grow unevenly; this saver shows that real behavior rather than hiding it.
Is a key needed?
No — it is a pure local computation.
Is it free?
Yes — free, no download, in your browser.
What happens if values are inserted in sorted order?
Each new value goes to the same side of the last, so the tree becomes a chain and operations take time proportional to the number of items rather than its logarithm.
What is an in-order traversal?
It visits the left subtree, then the node, then the right subtree. In a binary search tree this yields the stored values in ascending order.
How do self-balancing trees fix the problem?
They rotate nodes after insertions or deletions so the two sides stay close to even in height, which keeps operations fast even in the worst case.

← All Science & Research screensavers