Announcements • Readings – Today: CSE 321 Discrete Structures • Structural Induction – 6 th edition: 4.3, 5 th edition: 3.4, – Friday: Winter 2008 • Counting – 6 th edition: 5.1, 5.2, 5 th edition: 4.1, 4.2 Lecture 15 Structural Induction Highlights from Lecture 14 Recursive Functions on Trees • Recursive Definitions • N(T) - number of vertices of T – Sets • N( ε ) = 0; N( • ) = 1 • 0 ∈ S; • N( • , T 1 , T 2 ) = 1 + N(T 1 ) + N(T 2 ) • if x ∈ S then x+2 ∈ S – Strings • λ ∈ L • Ht(T) – height of T • w ∈ L, x ∈ {a, b} then wxx ∈ L • Ht( ε ) = 0; Ht( • ) = 1 – Trees • ε ∈ EBT • Ht( • , T 1 , T 2 ) = 1 + max(Ht(T 1 ), Ht(T 2 )) • if T 1 , T 2 ∈ EBT, then ( • , T 1 , T 2 ) ∈ EBT NOTE: Height definition differs from the text Base case H( • ) = 0 used in text More tree definitions: Fully And more trees: balanced binary trees Almost balanced trees • ε is a FBBT. • ε is a ABT. • if T 1 and T 2 are FBBTs, with Ht(T 1 ) = • if T 1 and T 2 are ABTs with Ht(T 2 ), then ( • , T 1 , T 2 ) is a FBBT. Ht(T 1 ) -1 ≤ Ht(T 2 ) ≤ Ht(T 1 )+1 then ( • , T 1 , T 2 ) is a ABT.
Is this Tree Almost Balanced? Structural Induction • Show P holds for all basis elements of S. • Show that if P holds for elements used to construct a new element of S, then P holds for the new element. Prove all elements of S are Prove that WFFs have the same number of left parentheses as right parentheses divisible by 3 • Basis: 21 ∈ S; 24 ∈ S; • Recursive: if x, y ∈ S, then x + y ∈ S; Well Formed Fomulae Fully Balanced Binary Tree • If T is a FBBT, then N(T) = 2 Ht(T) - 1 • Basis Step – T, F, and s, where is a propositional variable are in WFF • Recursive Step – If E and F are in WFF then ( ¬ E), (E ∧ F), (E ∨ F), (E → F) and (E ↔ F) are in WFF
Binary Trees Almost Balanced Binary Trees • If T is a binary tree, then N(T) ≤ 2 Ht(T) - 1 Let α = (1 + sqrt(5))/2 Prove N(T) ≥ α Ht(T) – 1 If T = ε : Base case: If T = ( • , T 1 , T 2 ) Ht(T 1 ) = x, Ht(T 2 ) = y Recursive Case: T = ( • , T 1 , T 2 ) N(T 1 ) ≤ 2 x , N(T 2 ) ≤ 2 y Let Ht(T) = k + 1 N(T) = N(T 1 ) + N(T 2 ) + 1 ≤ 2 x – 1 + 2 y – 1 + 1 Suppose Ht(T 1 ) ≥ Ht(T 2 ) ≤ 2 Ht(T) -1 + 2 Ht(T) – 1 – 1 Ht(T 1 ) = k, Ht(T 2 ) = k or k-1 ≤ 2 Ht(T) - 1 Almost Balanced Binary Trees N(T) = N(T 1 ) + N(T 2 ) + 1 ≥ α k – 1 + α k-1 – 1 + 1 ≥ α k + α k-1 – 1 [ α 2 = α + 1] ≥ α k+1 – 1
Recommend
More recommend