quiz5f03-sol-post

quiz5f03-sol-post - 2 n 1 Algebraic Equality(n 1 3 2(n 1 =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
10/24/03 Solution ********** CS373 Quiz 5 1) For the following grammar: S → aS | A A → bAc | d a) Give a leftmost derivation of aabdc. S→aS→aaS→aaA→aabAc→aabdc b) Give a derivation tree for abbdcc. =========> c) What language does this grammar accept? {a m b n dc n | m,n 0} 2) Prove by induction: n 3 +2n is divisible by 3 for all n 0. The Three basic steps must be clearly shown, and each step written in the inductive step must be justified. Basis : 0 3 +2(0) = 0 which is divisible by 3 Induction Assumption: assume n 3 +2n = 3k where k is some natural number (works for n) Inductive step: n 3 +2n = 3k where k is some natural number Inductive assumption n 3 +2n + 3(n 2 +n+1) = 3k + 3(n
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 +n+1) Algebraic Equality (n+1) 3 + 2(n+1) = 3(k+n 2 +n+1) Regrouping Works for n+1, QED 3) Give a CFG to accept an even or odd PALINDROME, where Σ = {a,b} S → aSa | bSb | a | b | ε 4) Give a CFG to accept the language {a n b m | n≠m} S → aSb | A | B A → aA | a B → bB | b 5) A homework problem: Find a context free grammar for L {a n b m : 0 ≤ n ≤ m+3}, ∑ = {a, b}. n a = n could be larger than n b = m by an amount of 1, 2, or 3. Otherwise it is smaller or equal to n b = m. S → aSb | A | B // n a = n b in L A → aaa | aa | a | λ // 0 ≤ n a – n b ≤ 3 in L B → bB | b // n a < n b in L...
View Full Document

Ask a homework question - tutors are online