Trees as Recursive Structures

Week 8, Monday

February 23, 2026

PACING OVERVIEW (80 min total)

Part 1: Wordle Hook (10 min)

  • Play 1-2 rounds of Wordle as a class
  • Brief discussion: what makes a good guess?
  • Introduce the idea that strategy = decision tree

Part 2: Jotto Activity (25 min)

  • Explain rules and scoring (5 min)
  • Hand out card decks, groups design strategies (15 min)
  • Debrief: what first guess did you choose? why? (5 min)

Part 3: Tree Definitions (15 min)

  • “Why Trees?” slide - quick tour of applications
  • Knuth quote + “what’s special?” (connected, acyclic)
  • Tree Terminology discovery questions (students answer)
  • Vocabulary reference slide (skim - definitions are intuitive)

Part 4: Binary Trees & Recursion (20 min)

  • Binary tree definition and recursive structure
  • Height/node count relationship
  • Why height matters for efficiency
  • Connect back to Wordle/Jotto: height = worst-case guesses

Part 5: Wrap-up (10 min)

  • Back to Wordle: decision tree perspective
  • Summary slide
  • Preview BSTs (Wednesday)

Let’s Play Wordle!

I’m thinking of a 5-letter word.

You have 6 guesses.

After each guess, I’ll tell you:

  • 🟩 Green: Right letter, right position
  • 🟨 Yellow: Right letter, wrong position
  • ⬜ Gray: Letter not in word

Let’s play as a class!

What Strategy Did We Use?

Think about how we played:

  • What made a guess “good”?
  • How did we narrow down possibilities?
  • Did we have a system, or was it intuition?

The Strategy Question

Every guess splits the remaining possibilities.

Guess Feedback Words eliminated
CRANE ⬜🟨⬜⬜🟩 Most words without R and E in those spots
STORE 🟩⬜🟩🟨🟩 Now we know S, O, E positions + R somewhere

Good guesses split possibilities evenly.

Visualizing the Strategy

What if we drew every possible game?

                         SALET (first guess)
                        /       |        \        ...
                 🟩⬜⬜⬜⬜    🟨⬜⬜⬜⬜    🟩🟩⬜⬜⬜     ...
                    /           |            \
      SHIRK, SHOWY, SPICY   CRISP, MUSIC   SAPPY, SANDY
      SWORN, SNOWY, ...     PRISM, ...     SAUCY, ...

Each follow-up guess is consistent with prior feedback.

Each path from top to bottom is one game. This is a tree!

The Wordle Decision Tree

This structure has a name: a decision tree.

  • Root: First guess
  • Branches: Possible feedback patterns (there are _______)
  • Internal nodes: Follow-up guesses
  • Leaves: The answer (game over!)

The height of this tree = worst-case guesses needed.

The Optimal Strategy Question

Question: What first guess gives the best tree?

What does best mean?

Research answer: SALET, REAST, CRATE, TRACE

3-Letter Jotto: Let’s Build a Strategy

The setup:

  • There are 16 possible secret words
  • You guess a word; the response is the count of letters in common (0, 1, 2, or 3)
  • You can only guess words that are still consistent with previous responses

Your task: Design a strategy — an algorithm that tells you what to guess in every situation, for any secret word.

Specify your strategy:

  1. What’s your first guess?
  2. For each possible response (0, 1, 2, or 3), what do you guess next?
  3. And so on, until you’ve identified the secret word.

Jotto Scoring Examples

Secret Guess Score Why
FOX JOG 1 O matches
DEW YAK 0 No letters in common
NIP INK 2 I and N match
WOO MOB 1 O matches (counted once)

The 16 Words

DEW  FOX  GEL  INK
JOG  MOB  NAP  NIP
NOR  NUT  OAT  OIL
PUG  SOY  WOO  YAK

Example: First Guess NIP

0 1 2 3 NIP DEW FOX GEL JOG MOB OAT SOY WOO YAK (9 words) NOR NUT OIL PUG (4 words) INK NAP (2 words) NIP (done!)

Each pile contains words consistent with that score.

What Strategy Did You Discover?

Discussion questions:

  • What makes a “good” first guess?
  • What happens if you guess CAT, then BAT, then HAT?
  • Can you always win in 2 guesses? Why or why not?

Why Trees?

Trees appear everywhere in computer science:

Domain Tree Structure
File systems Directories contain subdirectories
HTML/DOM Elements contain child elements
Decision making Each choice leads to sub-choices
Classification “Is it X? If yes, go left…”
Game AI Possible moves branch into more moves

Trees: The Most Important Nonlinear Structure

“Trees are the most important nonlinear structure in computer science.”

— Donald Knuth, The Art of Computer Programming

What’s special about this structure? ________________________

1 2 3 4 5 6

Tree Terminology

a b c d e f g h i j
  • One of the vertices is called the root of the tree. Guess which one it is.
  • Make an English word containing the names of the vertices that have a parent but no sibling.
  • How many parents does each vertex have?
  • Which vertex has the fewest children?
  • Which vertex has the most ancestors? descendants?
  • What is d’s depth? What is d’s height?
  • List all the vertices in b’s left subtree.
  • List all the leaves in the tree.

Tree Vocabulary (reference)

a b c d e f g h i j
  • root: the single node with no parent
  • leaf: a node with no children
  • child: a node pointed to by me
  • parent: the node that points to me
  • sibling: another child of my parent
  • ancestor: my parent or my parent’s ancestor
  • descendant: my child or my child’s descendant
  • subtree: a node and its descendants
  • depth of node x: number of edges on path from root to x
  • height of node x: number of edges on longest path from x to a leaf

d-ary Tree Definition

A d-ary tree T is either:

  • _______________________________________

OR

  • _______________________________________