Open the editor

Computer science · High school

Binary Search Tree Slides

Free animated slides, ready to teach: 6 slides where every step appears on a click and the diagrams move. Play them right here, present them full screen, or copy them into your account to edit.

A real Tracé deck playing in your browser. No account needed.

What the lesson covers

In a binary search tree every node has smaller values in its left subtree and larger values in its right subtree. Students follow a search down the tree one comparison per level, insert new values and see why a balanced tree of a million items is only about 20 levels deep.

The slides, one by one

1 Binary search trees

Smaller left, larger right

How can a computer find one value among a million in 20 steps?

2 Each comparison chooses one branch

Search for 60: 3 comparisons

Left subtree smaller, right subtree larger

3 A balanced tree is shallow

Each level doubles the nodes

Insert in sorted order: a long chain

4 Building and searching a tree

Insert 50, 30, 70, 20, 40, 60, 80 into an empty BST. Then search for 45.

→ Each new value goes left if smaller, right if larger, until there is a gap

50 \text{ root};\ 30, 70 \text{ its children}
20, 40 \text{ under } 30;\ 60, 80 \text{ under } 70
45: 45 < 50 \to 30,\ 45 > 30 \to 40
45 > 40: \text{ empty right branch}

45 is not in the tree: found out after 3 comparisons

5 Quick check

An in-order traversal (left, node, right) of a BST lists the values…

  • In insertion order
  • Level by level
  • In random order
  • In ascending order
Show the answer

In ascending order

Everything left of a node is smaller and everything right is larger, so left–node–right gives sorted order.

6 What to remember

Left subtree < node < right subtree

Search: one comparison per level

\textsf{Balanced: about }\log_2 n\textsf{ levels}

In-order traversal gives sorted values

Challenge: What tree do you get if you insert 1, 2, 3, 4, 5 in that order, and why is it slow?

Every slide is built click by click: text, formulas and pictures come in one step at a time, so the class follows the reasoning instead of reading ahead. Graphs with sliders can be dragged live while you present.

Make your own version with AIChange the level, the numbers or the language: type the topic and get a new deck that moves in about 30 seconds. Free, no account needed.

Questions teachers ask

How do you search a binary search tree?

Start at the root. If the target is smaller go left, if larger go right, and repeat until you find it or reach an empty branch. Each comparison drops a whole subtree, so a balanced tree needs about log₂ n steps.

Are these slides really free?

Yes. Watch them on this page or present them full screen with no account. Making your own copy to edit is free too.

Can I change the slides before my lesson?

Yes. Press "Make my own copy" and the deck becomes one of your projects in the Tracé editor, where you can change the text, the numbers, the colours or the order of the clicks.

Do they work on a classroom projector or an interactive whiteboard?

Yes. They run in the browser on any laptop, so anything that shows your screen works. Press the right arrow or click to go to the next step.