You are on page 1of 22

Syllabus for sem

Automata
1.Finite State Automata
2.Push Down Automata
3.Linear Bounded Automata
4.Turing Machine
Grammar
1.Regular Grammar
2.Context Free Grammar
3.Context Sensitive
Grammar
Language
1.Regular Language
2.Context Free Language
3.Context Sensitive Language
4.Recursive Language
5.Recursively Enumerable Language
6.Beyond RE
Chomsky Normal Form

1.Give the definition of DFA . (5)

DFA (Deterministic finite automata)


○ DFA refers to deterministic finite automata. Deterministic refers to the uniqueness of the
computation. The finite automata are called deterministic finite automata if the machine
is read an input string one symbol at a time.
○ In DFA, there is only one path for specific input from the current state to the next state.
○ DFA does not accept the null move, i.e., the DFA cannot change state without any input
character.
○ DFA can contain multiple final states. It is used in Lexical Analysis in Compiler.
In the following diagram, we can see that from state q0 for input a, there is only one path which
is going to q1. Similarly, from q0, there is only one path for input b going to q2.
2. Consider the following NFA

𝛅 ϵ a b

→p {r} {q} {p,q}

q Ⲫ {p} Ⲫ

*r {p,q} {r} {Ⲫ}

i. Complete the ϵ closure in each state . 2 marks


ii. Give the set of all strings of length 3 or less accepted by the automation. 2 marks
iii. Connect the automata into DFA 5 marks

3. Give the regular expression for all strings with


i. 1101 as substring
ii. 1101 is not substring

4. Design a dfa over alphabet {0,1} that accepts all strings with even number of 1 (3)

5.
ϵ a b c

p {q, r} Ⲫ {q} {r}

q Ⲫ {p} {r} {p, q}

*r Ⲫ Ⲫ Ⲫ Ⲫ
I. Compute ϵ closure of each state (3)
ϵ(p) = {p,q,r}
ϵ(q) = {q}
ϵ(r) = {r}
ii. Give set of all strings of length 3 or less accepted by the automation (2)
Straight of set 3 -
a, c, aa, ab, ac, ca, cb, cc, ba, bb, bc, cca, ccb, ccc, aaa, aab, aac, aba, abb, abc, baa, bab,
bac, bba, bca, bca, bcc, bbb, bbc, caa, caa, cab, cac, cba, cbb, cbc.

iii. Connect the automation to DFA (3)

𝛅 a b c

p {q,q,r} {q} {r}

q {p,q,r} {r} {p,q,r}


*r {r} {r} {r}

{p,q,r} {p,q,r} {p,q,r} {p,q,r}


6. Design a DFA over {0, 1} that accepts even no of 0 and 1. (4)

7. Consider the regular expression (0+1)* 10(0+1)* + (0+1)* 11(0+1)* use dissributive law
to simplify the expression. (4)
Ans:
(0+1)* 10(0+1)* +(0+1)* 11(0+1)*
(0+1)* (10(0+1)* 11(0+1)*)
(0+1)* (10+11)(0+1)*
(0+1)* 1(0+1)(0+1)*
(0+1)* 1(0+1)*

8. Prove of disprove (4)


i. (R + S)* = R* + S*
(R+S)* = R* + S*
Let R = ‘a’ , S = ‘b’
(R + S)* = (a + b)*
= a* + b* + (ab)*
R* + S* = a* + b* ≠ L.H.S
ii. (RS + R)*RS = (RR* + S*)
L.H.S =
9. Define Pumping lemma. Prove the theorem of pumping lemma. (6)

The pumping lemma is a theorem in formal language theory that can be used to prove that a
given language is not regular. The theorem states that for any regular language, there exists a
positive integer n such that for any string x in the language with length at least n, there exist
strings u, v, and w such that:

● x = uvw
● |uv| ≤ n
● |v| > 0
● for all i ≥ 0, uv^iw ∈ L

where L is the language in question.

In other words, the pumping lemma states that for any regular language, it is possible to "pump"
a middle section of a string any number of times and still end up with a string that is in the
language.
To prove the pumping lemma, we can use a proof by contradiction. Assume that there exists a
regular language L that does not satisfy the pumping lemma. This means that there exists a
positive integer n such that for some string x in L with length at least n, there do not exist strings
u, v, and w such that the above conditions are satisfied.

We can construct a contradiction by considering the string x^n. This string is in L, since L is
regular. However, the string x^n cannot be pumped, since there do not exist strings u, v, and w
such that the above conditions are satisfied. This is a contradiction, since L is assumed to be
regular.

Therefore, the pumping lemma must be true.

The pumping lemma is a useful tool for proving that a given language is not regular. It is often
used in conjunction with other techniques, such as the Myhill–Nerode theorem, to prove that a
given language is not regular.

Here are some examples of languages that are not regular:

● The language of all strings of balanced parentheses.


● The language of all strings of all the digits 0 and 1, where the number of 0s is equal to
the number of 1s.
● The language of all strings of all the letters a and b, where the number of a's is divisible
by 3.

These languages are not regular because they cannot be pumped. For example, the language
of all strings of balanced parentheses cannot be pumped because there is no way to pump a
middle section of a string of balanced parentheses and still end up with a string of balanced
parentheses.

The pumping lemma is a powerful tool that can be used to prove that a given language is not
regular. It is often used in conjunction with other techniques to prove that a given language is
not regular.

Other result from Chatgpt:

The pumping lemma is a useful tool in formal language theory used to prove that a language is
not regular. It states that for any regular language L, there exists a constant p (the "pumping
length") such that any string s in L with a length of at least p can be divided into five parts, s =
xyzuv, satisfying the following conditions:

1. The length of xyuv is at most p.


2. The length of y and/or v is greater than 0.
3. For all integers i ≥ 0, the string xyizuv is also in L.
To prove that a language L is not regular using the pumping lemma, we need to demonstrate
that for any pumping length p, there exists a string s in L that cannot be pumped (i.e., condition
3 fails).

Here is an example of how the pumping lemma can be used to prove that the language L =
{0^n1^n | n ≥ 0} (the language of all strings consisting of any number of 0's followed by an equal
number of 1's) is not regular:

1. Assume that L is a regular language, and let p be the pumping length.


2. Consider the string s = 0^p1^p. Clearly, s is in L and its length is at least p.
3. According to the pumping lemma, s can be divided into five parts: s = xyzuv, where the length
of xyuv is at most p, and the length of y and/or v is greater than 0.
4. We consider the possible cases for the placement of y and v within the string s:

a) Both y and v consist only of 0's (i.e., xyuv contains only 0's).
In this case, pumping the string by increasing i (i.e., xyizuv, where i > 0) will result in more 0's
being added before the 1's. As a result, the string will no longer be in L since the number of 0's
will exceed the number of 1's.

b) Both y and v consist only of 1's (i.e., xyuv contains only 1's).
Similarly, pumping the string by increasing i (i.e., xyizuv, where i > 0) will lead to more 1's after
the initial block of 0's. Consequently, the number of 1's will exceed the number of 0's, causing
the string to be not in L.

c) Both y and v contain both 0's and 1's.


In this case, pumping the string by increasing i (i.e., xyizuv, where i > 0) will cause the order of
the 0's and 1's to be disturbed. Thus, the resulting string will not have an equal number of 0's
and 1's, and it will not be in L.

5. In all cases, we have demonstrated that the pumped string xyizuv is not in L for some i > 0.
Hence, L cannot be a regular language based on the pumping lemma.

This proof shows that the language L = {0^n1^n | n ≥ 0} is not regular by using the pumping
lemma. Similar techniques can be applied to prove that other languages are not regular as well.
Suggestions:

● DFA, NFA- definition, difference, example.


● Designing DFA
● Convert epsilon-NFA to DFA
● Write the regular expression from DFA
● Algorithm to Minimize a DFA
● Minimize a given DFA
● A grammar is given, and a string is given. Find the leftmost and rightmost derivation
● Define Epsilon transition
● Ambiguous grammar and CFG
● Describe the extended transition function of NFA, DFA and Epsilon-NFA

● Chomsky Normal Form


● Parse tree and derivation
● Deterministic and Non deterministic PDA
● Is it true that non deterministic PDA is more powerful than that of Deterministic PDA.
Justify.
● Rules for converting CFG to PDA

Suggestions:

1. DFA, NFA-definition, difference, example.

Sure. Here is a brief definition of DFA and NFA, along with their
differences and an example.

Deterministic finite automata (DFA) are a type of abstract machine


that can be used to recognize patterns in strings. They are called
deterministic because, given a particular state and input symbol,
there is only one possible next state. This makes them relatively hard
to implement in software.

Non-deterministic finite automata (NFA) are similar to DFAs, but they


allow for multiple possible next states for a given input symbol. This
makes them more powerful than DFAs, but also more easier to
implement.

The main difference between DFAs and NFAs is that DFAs can only
have one next state for each input symbol, while NFAs can have
multiple next states. This means that NFAs can recognize a wider
range of strings than DFAs, but they are also more easier to
implement.

Here is an example of a DFA and an NFA that recognize the same set
of strings:

```
DFA:

Start state: q0

States: q0, q1, q2

Input symbols: a, b

Transitions:

q0 -> q1 on a
q0 -> q2 on b
q1 -> q2 on a
q2 -> q2 on a, b

Accepting state: q2

NFA:

Start state: q0
States: q0, q1, q2

Input symbols: a, b

Transitions:

q0 -> {q1, q2} on a


q0 -> q2 on b
q1 -> q2 on a
q2 -> q2 on a, b

Accepting state: q2
```

As you can see, the DFA and the NFA have the same states and
transitions, but the NFA allows for multiple possible next states for a
given input symbol. This means that the NFA can recognize strings
that the DFA cannot, such as the string "aa".

DFAs and NFAs are both important tools in computer science. DFAs
are often used in compilers and other software tools, while NFAs are
often used in natural language processing applications.

2. Designing DFA Convert epsilon-NFA to DFA

https://youtu.be/h4v7x0IMhtI

3. Write the regular expression from DFA

Neso Academy
4. Algorithm to Minimize a DFA Minimize a given DFA

There are many algorithms for minimizing a DFA. One of the most
common algorithms is the Hopcroft minimization algorithm. This
algorithm works by iteratively merging states that are
indistinguishable.

The following is a step-by-step description of the Hopcroft


minimization algorithm:

1. Initialize the equivalence classes. Initially, each state is in its own


equivalence class.
2. Find all pairs of indistinguishable states. Two states are
indistinguishable if they accept the same set of strings. This can be
determined by checking whether the two states have the same
transition function for all input symbols.
3. Merge all pairs of indistinguishable states. For each pair of
indistinguishable states, merge the two states into a single
equivalence class.
4. Repeat steps 2 and 3 until no more pairs of indistinguishable
states can be found.
5. The resulting equivalence classes are the minimized DFA

The following is an example of how the Hopcroft minimization


algorithm can be used to minimize a DFA.

```
Initial DFA:

q0 -> q1 | q2 on 0
q0 -> q3 | q4 on 1
q1 -> q5 on 0
q2 -> q5 on 1
q3 -> q6 on 0
q4 -> q6 on 1
q5 -> q7 on 0, 1
q6 -> q7 on 0, 1
q7 is accepting

Minimized DFA:

q0 -> q1 | q2 | q3 | q4 on 0
q0 -> q5 | q6 on 1
q1, q2, q3, q4, q5, q6 -> q7 on 0, 1
q7 is accepting
```

As you can see, the minimized DFA has only 6 states, compared to
the original DFA which had 8 states. This is a significant reduction in
the number of states, which can lead to improved performance.

5. Grammar is given, and a string is given. Find the leftmost and


rightmost derivation

https://youtu.be/kFJaUtkn9wo

6. Define Epsilon transition Ambiguous grammar and CFG

Sure. Here are the definitions of Epsilon transition, Ambiguous


grammar, and CFG:

* **Epsilon transition:** An epsilon transition is a transition in a finite


state machine that does not consume any input symbols. It is
represented by the Greek letter epsilon (ε). Epsilon transitions are
often used to represent optional symbols in grammars.
* **Ambiguous grammar:** A grammar is said to be ambiguous if
there are two or more different parse trees that can be generated for
the same input string. Ambiguous grammars can be difficult to parse
and can lead to errors in compilers and other software tools.
* **CFG:** A context-free grammar (CFG) is a type of grammar that
can be used to describe the syntax of a language. CFGs are made up
of productions, which are rules that specify how strings can be
generated from a set of terminals and non-terminals. CFGs are a
powerful tool for describing the syntax of programming languages
and other formal languages.

Here are some additional details about each of these terms:

* **Epsilon transition:** Epsilon transitions can be used to represent


optional symbols in grammars. For example, the grammar rule `S -> a
| ε` means that the non-terminal `S` can be replaced by the terminal
`a` or by nothing (i.e., an empty string).
* **Ambiguous grammar:** Ambiguous grammars can be difficult to
parse because there may be multiple ways to generate the same
input string. For example, the grammar rule `S -> a B | a C` means that
the non-terminal `S` can be replaced by the terminal `a` followed by
the non-terminal `B` or by the terminal `a` followed by the
non-terminal `C`. This grammar is ambiguous because the input
string `aa` can be generated in two different ways: `aa` can be parsed
as `a (B a)` or as `a (C a)`.
* **CFG:** CFGs are a powerful tool for describing the syntax of
programming languages and other formal languages. They are used
in compilers, parser generators, and other software tools. CFGs are
also used in theoretical computer science to study the properties of
languages and to develop algorithms for parsing and other tasks.

I hope this helps!


7. Describe the extended transition function of NFA, DFA and
Epsilon-NFA

Sure. The extended transition function is a function that takes a state


and a string of input symbols, and returns the set of states that can
be reached from the given state by reading the given string of input
symbols.

* **DFA:** The extended transition function of a DFA is simply the


function that maps a state and a symbol to the next state. For
example, if the current state is `q0` and the input symbol is `a`, then
the next state is `q1`.
* **NFA:** The extended transition function of an NFA is more
complex. It maps a state and a string of symbols to a set of states.
For example, if the current state is `q0` and the input string is `ab`,
then the next states could be `q1` or `q2`.
* **Epsilon-NFA:** An epsilon-NFA is a type of NFA that can also
move to other states without consuming any input symbols. This is
done using the epsilon symbol, which is represented by the Greek
letter `ε`. The extended transition function of an epsilon-NFA maps a
state and a string of symbols to a set of states, including states that
can be reached by consuming epsilon symbols.

The extended transition function is a powerful tool that can be used


to analyze and design finite automata. It can be used to prove that a
finite automaton accepts a given language, to find the minimum state
DFA for a given NFA, and to convert between different types of finite
automata.

Here is an example of the extended transition function for an NFA:

```
State | Input | Next states
-------|--------|------------
q0 | a | {q1, q2}
q0 | b | q2
q1 | a | q2
q2 | a, b | q2
```

As you can see, the extended transition function for this NFA maps
the current state and the input symbol to a set of next states. For
example, if the current state is `q0` and the input symbol is `a`, then
the next states are `q1` and `q2`.

The extended transition function can be used to analyze the behavior


of an NFA. For example, we can use it to determine whether an NFA
accepts a given string. We can also use it to find the minimum state
DFA for a given NFA.

8. Chomsky Normal Form Parse tree and derivation

Chomsky Normal Form (CNF) is a restricted form of context-free


grammars that is often used in theoretical computer science. CNF
grammars are much easier to analyze than general context-free
grammars, and they can be used to prove important results about the
theory of computation.

A parse tree is a graphical representation of a derivation sequence of


a sentential form. In CNF, the parse tree must have the following
properties:

* The root node is always a non-terminal symbol.


* The leaf nodes are always terminal symbols.
* Every internal node has exactly two children.
* The left child of an internal node is a non-terminal symbol.
* The right child of an internal node is a terminal symbol.

A derivation is a sequence of productions that can be used to


generate a string from the start symbol of a grammar. In CNF, a
derivation must have the following properties:

* The first production in the derivation must be the start symbol of the
grammar.
* Each subsequent production must be a production that can be
applied to the right-hand side of the previous production.
* The last production in the derivation must be a terminal symbol.

The following is an example of a parse tree and derivation in CNF:

```
Grammar:

S → AB
A→a
B→b

Parse Tree:

S
/ \
A B
\ /
a b
```

Derivation:

```
S → AB
A→a
B→b
```

CNF grammars are a powerful tool for analyzing and proving results
about the theory of computation. They are used in many areas of
computer science, including compilers, parser generators, and
artificial intelligence.

9. Deterministic and Non deterministic PDA

Deterministic pushdown automata (DPDA) and non-deterministic


pushdown automata (NPDA) are two types of pushdown automata. A
pushdown automaton is a finite state machine that can read and
write symbols from a stack. DPDAs and NPDAs differ in the way that
they can move from one state to another.

In a DPDA, there is only one possible next state for each combination
of current state and input symbol. This makes DPDAs easier to
implement than NPDAs, but also limits their expressive power.
NPDAs, on the other hand, can have multiple possible next states for
each combination of current state and input symbol. This makes
NPDAs more powerful than DPDAs, but also more difficult to
implement.

Here is an example of a DPDA that recognizes the language of all


strings that contain an equal number of 'a' and 'b' symbols:

```
Start state: q0

States: q0, q1, q2


Input symbols: a, b

Stack symbols: A, B

Transitions:

q0 on a -> q1, push A


q0 on b -> q1, push B
q1 on a -> q2, pop A
q1 on b -> q2, pop B
q2 on any symbol -> accept
```

In this example, the DPDA starts in state q0. When it reads an 'a'
symbol, it moves to state q1 and pushes an 'A' symbol onto the stack.
When it reads a 'b' symbol, it moves to state q1 and pushes a 'B'
symbol onto the stack. When it reaches the end of the input string, it
moves to state q2 and pops symbols off the stack until the stack is
empty. If the stack is empty, then the DPDA accepts the input string.
Otherwise, the DPDA rejects the input string.

Here is an example of an NPDA that recognizes the same language


as the DPDA above:

```
Start state: q0

States: q0, q1, q2

Input symbols: a, b

Stack symbols: A, B
Transitions:

q0 on a -> {q1, q2}, push A


q0 on b -> {q1, q2}, push B
q1 on a -> q2, pop A
q1 on b -> q2, pop B
q2 on any symbol -> accept
```

In this example, the NPDA starts in state q0. When it reads an 'a'
symbol, it moves to states q1 and q2 and pushes an 'A' symbol onto
the stack. When it reads a 'b' symbol, it moves to states q1 and q2
and pushes a 'B' symbol onto the stack. When it reaches the end of
the input string, it moves to state q2 and pops symbols off the stack
until the stack is empty. If the stack is empty, then the NPDA accepts
the input string. Otherwise, the NPDA rejects the input string.

As you can see, the NPDA is more powerful than the DPDA because it
can accept strings that the DPDA cannot. However, the NPDA is also
more difficult to implement because it has to keep track of multiple
possible next states.

10. Is it true that non deterministic PDA is more powerful than that of
Deterministic PDA? Justify.

Yes, non-deterministic pushdown automata (NPDAs) are more


powerful than deterministic pushdown automata (DPDAs). A NPDA
can accept any language that can be accepted by a DPDA, but a
DPDA cannot accept any language that can be accepted by a NPDA.

To see why, consider the following example. Let L be the language of


all strings over the alphabet {a,b} that contain an equal number of a's
and b's. This language can be accepted by a NPDA by using the
following strategy:

1. Push an a onto the stack for each a that is read.


2. Pop a b off the stack for each b that is read.
3. If the stack is empty at the end of the input, then the string is
accepted.

This strategy can be implemented in a NPDA by using


non-determinism to try all possible ways of pushing and popping a's
and b's onto the stack.

A DPDA cannot accept this language, because it cannot keep track of


the number of a's and b's that have been read. A DPDA can only read
one symbol at a time, and it cannot look ahead to see what symbols
are coming up next.

Therefore, a NPDA is more powerful than a DPDA.

Here are some other examples of languages that can be accepted by


NPDAs but not by DPDAs:

* The language of all strings that are palindromes.


* The language of all strings that are balanced parentheses.
* The language of all strings that are context-free.

These languages can all be accepted by NPDAs by using the same


strategy of pushing and popping symbols onto the stack. However,
this strategy cannot be implemented in a DPDA because it cannot
keep track of the structure of the input string.

11. Rules for converting CFG to PDA


The following are the rules for converting a context-free grammar
(CFG) to a pushdown automaton (PDA):

1. **Convert the CFG to Greibach normal form (GNF)**. This is a


normal form of a CFG in which all productions are of the form A → aB
or A → ε, where A is a non-terminal, a is a terminal, and B is a
sequence of non-terminals and terminals.
2. **Create a PDA with a single state.** The initial state of the PDA
will be the same as the start symbol of the CFG.
3. **For each production in the CFG, add a transition to the PDA.**
The transition will have the following form:

```
(current state, input symbol, top of stack) → (new state, new top of
stack)
```

The current state is the state of the PDA before the transition. The
input symbol is the next symbol in the input string. The top of stack is
the symbol at the top of the PDA's stack before the transition. The
new state is the state of the PDA after the transition. The new top of
stack is the symbol that will be pushed onto the PDA's stack after the
transition.

The transitions for the productions in the CFG can be determined


using the following rules:

* For a production of the form A → aB, the transition will be (q, a, A)


→ (q, B).
* For a production of the form A → ε, the transition will be (q, ε, A) →
(q, ε).
4. **Accept the input string if the PDA reaches a final state after
reading the entire input string.** The PDA will accept the input string
if it reaches a final state after reading the entire input string. A final
state is a state that is marked as a final state in the PDA.

The following is an example of how to convert a CFG to a PDA.

```
CFG:
S → aB | bA | ε
B→a|b
```

GNF:
```
S → aB | bA
B→a|b|ε
```

PDA:
```
Initial state: q
Final states: q
Transitions:
(q, a, S) → (q, B)
(q, b, S) → (q, A)
(q, a, B) → (q, ε)
(q, b, B) → (q, ε)
```

The PDA accepts the input string if it reaches the final state q after
reading the entire input string.

You might also like