Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (648.57 KB, 5 trang )
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
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.
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.