Download presentation

Presentation is loading. Please wait.

Published byCiera Swalwell Modified over 2 years ago

1
Structural Induction Warm-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 y SCR (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=εand x is balanced. Induction step. Fix n, suppose |x| = n+1>0 and for all m≤n and any y of length m, if y SCR then y is balanced. Case 1. The count never reaches 0 except at the end. Then x=(y) where y SCR (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.

Similar presentations

Presentation is loading. Please wait....

OK

POSITIVE AND NEGATIVE NUMBERS

POSITIVE AND NEGATIVE NUMBERS

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on carbon and its compounds elements Ppt on bermuda triangle for class 9 Ppt on barack obama leadership profile Free ppt on control and coordination Ppt on area of parallelogram and triangles and quadrilaterals Ppt on liberal education Ppt on life and works of william shakespeare Ppt on voice command activated robot Ppt on atrial septal defect repair Ppt on beer lambert law spectrophotometry