Discrrete mathematics for computer science structural induction warmup

5 76 0
Discrrete mathematics for computer science structural induction warmup

Đang tải... (xem toàn văn)

Thông tin tài liệu

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 at the left end of the string, adding for each (, subtracting for each ), gives 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 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 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 after y, to after z without ever going negative 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 The count never reaches except at the end Then x=(y) where y SCR (why?) But |y|=|x|-2 and by IH y is balanced By construction rule so is x • Case x=yz where the y and z are nonempty and the count goes to 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 ... balanced, then x SCR • Structural Induction Base case: x=ε Then count begins and ends 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... 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,... that a string s∈{ ), ( }* SCR iff starting from at the left end of the string, adding for each (, subtracting for each ), gives at the end without ever going negative • Theorem: A string of parentheses

Ngày đăng: 22/03/2019, 12:10

Mục lục

  • Slide 1

  • “Balanced String of Parentheses”

  • Slide 3

  • If a string of parentheses x is balanced, then x SCR.

  • If x SCR then x is balanced.

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan