1 / 5

Structural Induction Warm-Up

Structural Induction Warm-Up. “Balanced String of Parentheses”. Base case: The empty string εis balanced Constructor rules: C1: If x is balanced then so is ( x ) , that is, the result of writing a “ ( “, then x , then “ ) ” C2: If x and y are balanced then so is xy.

werner
Download Presentation

Structural Induction Warm-Up

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structural InductionWarm-Up

  2. “Balanced String of Parentheses” • Base case: • The empty string εis balanced • Constructor rules: • C1: If x is balanced then so is (x), that is, the result of writing a “(“, then x, then “)” • C2: If x and y are balanced then so is xy

  3. A String of Parentheses is Balanced iff it Satisfies the Counting Rule (SCR) Say that a string s∈{ ), ( }*SCR iff starting from 0 at the left end of the string, adding 1 for each (, subtracting 1 for each ), gives 0 at the end without ever going negative. Theorem: A string of parentheses is balanced iff it SCR.

  4. If a string of parentheses x is balanced, then x SCR. Structural Induction Base case: x=ε. Then count begins and ends 0 so x SCR. Induction case 1: x = (y) where y is balanced. Then ySCR (why?). Then the count for x is +1 after first(, +1 again after the last character of y, stays positive in between, and ends at 0 after the final ). Induction case 2: x = yz where y and z are balanced. Then y and z SCR and the count goes from 0, to 0 after y, to 0 after z without ever going negative.

  5. If x SCR then x is balanced. Proof by strong induction on |x|. Suppose x SCR. Base case: |x|=0. Then x=εandx is balanced. Induction step. Fix n, suppose |x| = n+1>0 and for all m≤n andany y of length m, if y SCR then yis balanced. Case 1. The count never reaches 0 except at the end. Then x=(y) where ySCR (why?). But |y|=|x|-2 and by IH y is balanced. By construction rule 1 so is x. Case 2. x=yz where the y and z are nonempty and the count goes to 0 after y. Then y and z are shorter than x and each SCR, so each is balanced by IH. Then x is balanced by construction rule 2.

More Related