Labs / Computer Science
Binary Search Tree
Pick a value and insert it — every number finds its slot by going left when it is smaller and right when it is larger. Then run a search to watch the comparison path light up, or an in-order traversal to see the tree unspool into a sorted list. Click any node to search straight for it.
nodes 0height 0Ready
What to try
- Reset, then insert values in increasing order (10, 20, 30…). Why does the tree turn into a lopsided line instead of a bushy shape?
- How many comparisons does a search take in a balanced tree versus that lopsided one — and how does the height readout predict it?
- Run the in-order traversal. Why does visiting left, then node, then right always come out perfectly sorted?
- Search for a value that is not in the tree. Where does the path stop, and what does that tell you about where it would be inserted?
- Add nodes with Random until the tree is large. What happens to the height as the node count doubles?