Trees Continued

Week 8, Wednesday

February 25, 2026

3-Letter Jotto: Let’s Play

The setup:

DEW  FOX  GEL  INK
JOG  MOB  NAP  NIP
NOR  NUT  OAT  OIL
PUG  SOY  WOO  YAK
  • There are 16 possible secret words – you choose one.
  • I guess a word; You respond with the count of letters in common (0, 1, or 2). If I get 3, the game is over!
  • I will continue to guess until I guess your word.

The Play: Turn and face the back of the room.

My Strategy

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

What Strategy Did You Discover?

Discussion questions:

  • What makes a “good” first guess?
  • What happens if you guess NAP, then NIP, then NUT?
  • 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

  • _______________________________________

Special Trees

Complete Tree


Full Tree


Perfect Tree

Week 8 Summary

  • Trees are hierarchical structures with a root, children, and leaves
  • Binary trees have at most 2 children per node
  • Trees are recursively defined: a tree is empty OR a root with subtrees
  • Tree terminology: root, leaf, parent, child, sibling, ancestor, descendant, depth, height
  • Decision trees model sequences of choices