0% found this document useful (0 votes)
125 views

Exercises #1 (Solutions)

The document covers exercises on regular languages, context-free languages and pushdown automata. It includes examples of constructing NFAs and regular expressions for given languages and state transition diagrams. It also provides context-free grammars and pushdown automata for palindrome languages and proves properties of context-free grammar derivations.

Uploaded by

aliyaabulais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Exercises #1 (Solutions)

The document covers exercises on regular languages, context-free languages and pushdown automata. It includes examples of constructing NFAs and regular expressions for given languages and state transition diagrams. It also provides context-free grammars and pushdown automata for palindrome languages and proves properties of context-free grammar derivations.

Uploaded by

aliyaabulais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Automata, Computability, and Complexity

Nik (Yerdos) Zhanpeissov


Spring 2024

1 Regular Languages
Exercise 1.

You are given the following state transition diagram for the automaton N1 :

1 1

q0 1 q1 0 q2

q3

N1
1. Construct an NFA N2 that recognizes the language L(N2 ) = L(N1 )∗ .
2. Draw the corresponding state-transistion diagram of N2
Solution.
1
1
q ε q q
4 0 1

ε
0 0
ε
q3 q2 1

N2
3. Give a formal description of N2 as a 5-tuple.
Solution.
N2 = ({q0 , q1 , q2 , q3 , q4 }, {0, 1}, δ, q4 , {q1 , q2 , q4 })

1
0 1 ε
q0 {q3 } {q0 , q1 } ∅
q {q2 } ∅ {q0 }
δ= 1
q2 ∅ {q2 } {q0 }
q3 ∅ ∅ ∅
q4 ∅ ∅ {q0 }

Exercise 2.

You are given the following state transition diagram for the automaton N :

1 0
0, 1 0 1
q0 q1 q2 q3

N
1. Give a regular expression that describes the language L(N ).
Solution.
R = (0 ∪ 1)1∗ 0+ 1
2. Try to describe L(N ) in your own words.
Solution.
A string in L(N ) has to be of at least length 3. It can start with either 1
or 0 but has to end in 1. The last symbol has to be immediately preceded
by at least one 0. The first symbol can be followed by any number of 1s.

Exercise 3.

You are given the following regular expression R = (01)∗ ∪ 0∗ 1(10 ∪ ε)


1. Draw the state-transition diagram of the language L(R).
Solution.
q1 0 q2 1 q3
ε
ε
q0

ε
q3 q4 q5 q6
1 1 0

2
2. Determine which of the following strings are matched by R:
ε, 01, 110, 010, 001, 0101, 0001010, 1111111
Solution.
Accept: ε, 01, 110, 001, 0101
Reject: 010, 0001010, 1111111

2 Context-Free Languages
Exercise 4.

Suppose you have a context-free language that only includes strings which are
palindromes over the alphabet Σ = {x, y}:

1. Describe the corresponding context-free grammar.


Solution.
G = ({S}, {x, y}, R, S) with rules:
S → xSx | ySy | x | y | ε
2. Draw the state-transition diagram of the corresponding PDA.
Solution.
ε, ε → $
q0 q1 x, ε → x; y, ε → y

ε, ε → ε; x, ε → ε; y, ε → ε

q3 q2 x, x → ε; y, y → ε
ε, $ → ε

Exercise 5.

Prove that the derivation of any string of length n ≥ 1 in CNF takes exactly
2n − 1 steps.
Solution.
Since the context-free grammar is in Chomsky normal form, each step of a
derivation either adds exactly one non-terminal variable or changes exactly one
non-terminal variable to a terminal one (or to ε). Since n ≥ 1, the rule S → ε
can never occur in any derivation of the string, and there are exactly n steps
changing a non-terminal variable to a terminal one. All these non-terminal
variables are added one by one starting from the starting variable S resulting
in another n − 1 operations, in total 2n − 1.

3
Exercise 6.

Describe the language of the context-free grammar G = ({A, B}, {0, 1, 2}, R, A)
with rules:
A → 00A1 | B
B → ε | 22B
Solution.
{02n 22m 1n | n, m ≥ 0}

You might also like