ClassS04CS141/Notes 03 31

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

Leaves and interior nodes in binary trees

claim: In any binary tree where each interior node has two children, it is the case that #leaves = #interior nodes + 1.

We did an in-class exercise to try prove this claim. Students came up with inductive proofs and a direct counting argument. Instructor proposed the following proof:


proof: Put a coin on each leaf. Then repeat the following process:

For any interior node without a coin where each child has at least one coin, take a coin from each of the two children and put these two coins on the node.

When the process finishes, each leaf has no coins, each interior node has one coin, and the root has two coins.

Since the number of coins is the same before and after this process,

#leaves = #coins before = #coins after = #interior nodes + 1

Had some discussion of what constitutes a proof.

We discussed GeometricSums and the GrowableArray data structure.


ClassS04CS141 | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions
Last edited May 4, 2004 7:02 pm by Neal (diff)
Search: