Theory of Algorithms 2019 Practice session 4.
1. Let the grammar be S →AB A→0A1|01 B →1B0|10.
(a) Give a parse tree for word001110.
(b) Determine the language generated by this grammar.
2. Consider S→AS|A A→0A1|01.
(a) Give a parse tree and a leftmost derivation for word 01010011.
(b) Determine the language generated by this grammar.
3. Give CF-grammar for the following languages. Are these unambiguous?
(a) L={anbn+1:n≥0}
(b) L={anb2n:n≥0}
(c) Palindromes over {a,b}
(d) L={aibjck:i=j ori=ki, j, k≥0}
4. Are the following grammars unambiguous? Are the languages generated by them unambiguous?
(a) S →aSa|bSb|aa|bb|a|b
(b) S →T T|U T →0T|T0|# U →0U00|#
5. Let the alphabet be Σ = {0,1}, states of the pushdown automaton be Q = {A, B, C}, where A is the start state and C is the only accept state, let Z be the start symbol of the stack. The transition function is the following. δ(A,0, ε) = {(A, a)}, δ(A,1, ε) = {(A, b)}, δ(A, ε, ε) = {(B, ε)}, δ(B,0, a) = {(B, ε)}, δ(B,1, b) ={(B, ε)},δ(B, ε, Z) ={(C, ε)}.
(a) Give the possible computations of the automaton on word010.
(b) Does it accept word 0110?
(c) What is the language recognized by the automaton?
(d) Give a CF-grammar for this language.
6. Construct a pushdown automaton for the language of palindromes.
7. Create pushdown automata for the following languages.
(a) La={aibjck:i, j, k ≥0 andi+j=k}
(b) Lb={aibjck:i, j, k≥0 and j+k=i}
(c) Lc={aibjck:i, j, k≥0 andi+k=j}
8. Create a pushdown automaton for the language of proper parenthesisations.
9. Construct pushdown automata for the following languages.
(a) La={anbm: 2n=m≥1}
(b) Lb={anbm : 2n≥m≥n≥1}
10. Create a pushdown automaton from the following CF-grammar. S → aSa |bSb| aa |bb | a |b Give an accepting computation for the word ababa (if such a computation exists).
11. Consider the unambiguous CF- grammar given in the lecture for the arithmetic expressions.
(a) Give a parse tree for the word a+a+a+a.
(b) If the value of the expression is calculated using the parse tree, then in what order will the additions be executed?
(c) Extend the grammar so that substraction is also included. is szerepeljen benne!
(d) What is the parse tree ofa−a+a−anow? What is the order of execution of the operations?
12. Give a CF-grammar that generates all such proper expressions that contain multiplications, exponentations and parentheses. The grammar should be unambiguous and should confirm to the usual order of execution of operations (that is, without parentheses exponentation has precedence, and for example in case of 234 first 34 must be computed and then it will be the exponent of 2).