You are on page 1of 12

AUTOMATA AND COMPLEXITY THEORY

GROUP ASSIGNMENT GROUP 5

№ ID № Group Members
1. RNS-0077/21 SULTAN GUYE TESISO
2. RNS-8016/21 LEMESA GETACHEW BEDECHA
3. RNS-9586/21 KALKIDAN GERAWORK TESFA
4. RNS-6026/21 WENGELLEALEM DEREJE GEBREMARYAM
5. RNS-2005/21 MERON ALEMU DEKEBA

Submission date: January 24,2024


Instructor: Mohammedbirhan Abdulkadr
Questions on DFA,NFA,CFG,PDA
NPDA
1. Construct DFA with ∑ = {a, b} accepts all strings with an odd number of 'a's.

A. Start with an initial state labeled q0.


B. Create two states: q1 and q2.
C. From the initial state q0, label one transition with 'a' to q1 and another transition with
'b' back to q0.
D. From state q1, label one transition with 'a' back to q0 and another transition with 'b'
to q1.
E. From state q2, label one transition with 'a' to q2 and another transition with 'b' back to
q2.
F. Make q2 an accepting state.
The resulting DFA looks like this:
This DFA will only accept strings with an odd number of 'a's because when it receives an
'a', it moves from the initial state q0 to q1 and then loops back to q0. So, it alternates
between q0 and q1 for each 'a'. If there were an even number of 'a's, the final state q2
would not be reached, and the string would be rejected.
2. Construct DFA with ∑ = {0, 1} accepts all strings that have an even number '1's.

State transitions:

- From q0, if the input is '0', remain in q0. If the input is '1', move to q1.

- From q1, if the input is '0', remain in q1. If the input is '1', move back to q0.

- From q2, if the input is '0', remain in q2. If the input is '1', move back to q1.

Here's the DFA representation:

Explanation:

- Starting from q0, for every '0' encountered, the DFA stays in q0. For every '1' encountered,
it moves to q1.

- From q1, for every '0' encountered, the DFA stays in q1. For every '1' encountered, it goes
back to q0.
- From q2, as it represents an odd number of '1's, for every '0' encountered, the DFA stays in
q2. For every '1' encountered, it goes back to q1.

This DFA will accept all strings with an even number of '1's, as it reaches the accept state q1
after processing an even number of '1's and rejects any string with an odd number of '1's.

3. Construct an NFA with ∑ = {0, 1} that accepts all strings where the third character
from the end is 0.

Here is the representation of the NFA that accepts all strings where the third character from
the end is 0:

Initial state: q0

Accepting state: q4

Transitions:

- From q0 to q1 with input 0 or 1

- From q1 to q2 with input 0 or 1

- From q2 to q3 with input 0 or 1

- From q3 to q3 with input 1

-From q3 to q4 with input 0

-From q4 to q4 with input 0 or 1

This NFA has 5 states (q0, q1, q2, q3, q4) and uses the alphabet ∑ = {0, 1}.

To represent this NFA in a more visual way, you can use a state transition diagram or a table.
Here is a state transition table for the given NFA:

State | Input | Next State

-------------------------------
q0 |0 | q1

q0 |1 | q1

q1 |0 | q2

q1 |1 | q2

q2 |0 | q3

q2 |1 | q3

q3 |0 | q4

q3 |1 | q3

q4 |0 | q4

q4 |1 | q4

Transition function diagram:


Note: This NFA can be converted into a DFA by using the subset construction algorithm.

4.Construct an NFA with ∑ = {0, 1} that accepts all strings where the last character is 1.

State Q0:

- On input 0, stay in Q0.

- On input 1, go to state Q1.

State Q1:

- On input 0 or 1, stay in Q1.

Accepting state Q1.

Transition function diagram:

5.Construct the CFG for the language with at least one 'a' over the set ∑= {a, b}.
Start symbol: S

Production rules:

1. S -> a | aB | Ba | BaB

2. B -> a | b | aB | bB

Explanation:

- The start symbol S generates strings with at least one 'a'.

- Production rule 1 allows S to generate 'a' as a valid string.

- Production rule 1 also allows S to generate 'a' followed by B, 'B' followed by 'a', or 'B' followed
by 'a' and B. These rules ensure that 'a' appears at least once in the generated string.

- Production rule 2 allows B to generate 'a', 'b', 'a' followed by B, or 'b' followed by B. These rules
ensure that there can be any number of 'a' or 'b' following the initial 'a'.

Note: The CFG assumes that the generated strings are formed only using the terminals 'a' and
'b'.

6.Construct the CFG for the language with an equal number of 'a's and 'b's over the set ∑
= {a, b}.

Start symbol: S

Production rules:

1. S -> aSb | bSa | ε

Explanation:

- The start symbol S generates strings with an equal number of 'a's and 'b's.

- Production rule 1 allows S to generate a balanced pair of 'a' and 'b' by either:

- Generating an 'a', followed by another S recursively, and then a 'b'.

- Generating a 'b', followed by another S recursively, and then an 'a'.


- The production rule ε allows S to generate the empty string, symbolizing the case where there
are no 'a's or 'b's.

Note: The CFG assumes that the generated strings are formed only using the terminals 'a' and
'b'.

7.Design a PDA for accepting a language {a^nb^m | n>=m}.

PDA Description:

- The PDA will use a single stack to keep track of the number of 'a's encountered.

- The PDA will have two states: q0 (initial) and q1 (final).

Transition Table:

| Current State | Input Symbol | Top of Stack | Next State | Push/Pop |

| q0 |a |- | q0 | Push a |

| q0 |a |a | q0 | Push a |

| q0 |b |a | q0 | Pop a |

| q0 |b |- | q1 |- |

Explanation:

- The PDA starts at state q0 with an empty stack.

- When it encounters an 'a', it pushes it onto the stack.

- When it encounters a 'b' and the top of the stack is 'a', it pops the 'a' from the stack.

- If the stack is empty, and it encounters a 'b', it moves to the final state q1.

- If at any point the PDA reads an input symbol for which there is no transition defined in the
table, it gets stuck in an infinite loop and rejects the input.

Acceptance Criteria:
- The PDA accepts the input if it reads all the input symbols, ends in state q1, and the stack is
empty.

- The PDA rejects the input in all other cases.

Note: The PDA described here assumes that the input contains only the symbols 'a' and 'b'. If
there are other symbols in the input, additional transitions and/or conditions need to be added
to the transition table.

8.Design a PDA that accepts the language L over {0, 1} with an empty stack. L consists of
all strings of 0's and 1's in which the number of 0's is equal to the number of 1's. PDA
Description:

- The PDA will use a single stack to keep track of the number of 0's encountered.

- The PDA will have three states: q0 (initial), q1, and q2 (final).

Transition Table:

| Current State | Input Symbol | Top of Stack | Next State | Push/Pop |

| q0 |0 |- | q0 | Push Z |

| q0 |0 |Z | q0 | Push Z |

| q0 |1 |Z | q1 |- |

| q1 |1 |Z | q1 |- |

| q1 |0 |Z | q1 |- |

| q1 |ε |Z | q2 | Pop Z |

Explanation:

- The PDA starts at state q0 with an empty stack.

- When it encounters a '0', it pushes a symbol 'Z' onto the stack.

- When it encounters a '1', and the top of the stack is 'Z', it stays in state q1 and pops the
symbol 'Z' from the stack.
- At the end of the input, when it encounters ε (empty string) and the top of the stack is 'Z', it
moves to the final state q2 by popping the 'Z' from the stack.

- If at any point the PDA reads an input symbol for which there is no transition defined in the
table, or the stack is not empty at the end of the input, the PDA rejects the input.

Acceptance Criteria:

- The PDA accepts the input if it reads all the input symbols, ends in state q2, and the stack is
empty (i.e., the stack contains only the initial 'Z' symbol).

- The PDA rejects the input in all other cases.

Note: The PDA described here assumes that the input contains only the symbols '0' and '1', and
the stack is initially empty. If there are other symbols in the input or the stack is not initially
empty, additional transitions and/or conditions need to be added to the transition table.

9.Design an NPDA that accepts the language L over {a, b} where every 'a' is followed by
exactly two 'b's.

PDA Description:

- The NPDA will use a single stack to keep track of the number of 'b's encountered after each 'a'.

- The NPDA will have four states: q0 (initial), q1, q2, and q3 (final).

Transition Table:

| Current State | Input Symbol | Top of Stack | Next State(s) Push/Pop

| q0 |a |- | q1, q2 | Push a |

| q1 |b |a | q3 | Pop a, Push b twice |

| q2 |b |a | q1 | Pop a, Push b |

Explanation:

- The NPDA starts at state q0 with an empty stack.


- When it encounters an 'a', it can transition non-deterministically to either state q1 or q2
without popping anything from the stack. This allows for branching and tries all possible paths.

- If the NPDA transitions to state q1, it expects to encounter two 'b's after the 'a'. It pops the 'a'
from the stack and pushes two 'b's onto the stack. If it successfully reads two 'b's after the 'a', it
moves to the final state q3.

- If the NPDA transitions to state q2, it expects to encounter only one 'b' after the 'a'. It pops the
'a' from the stack and pushes one 'b' onto the stack. It then transitions back to state q1, allowing
for the possibility of a second 'b' after the first one.

- If at any point the NPDA reads an input symbol for which there is no transition defined in the
table, or the stack becomes empty before the expected number of 'b's are encountered, the
NPDA rejects the input.

Acceptance Criteria:

- The NPDA accepts the input if it reads all the input symbols, ends in state q3, and the stack is
empty.

- The NPDA rejects the input in all other cases.

Note: The NPDA described here assumes that the input contains only the symbols 'a' and 'b'. If
there are other symbols in the input, additional transitions and/or conditions need to be added
to the transition table.

10.Design an NPDA that accepts the language L over {0, 1} where the number of '0's is less
than the number of PDA Description:

- The NPDA will use a single stack to keep track of the difference between the number of '0's
and '1's encountered.

- The NPDA will have four states: q0 (initial), q1, q2, and q3 (final).

Transition Table:

| Current State | Input Symbol | Top of Stack | Next State(s) Push/Pop |

| q0 |0 |- | q1 | Push 0 |

| q0 |1 |- | q0 |- |
| q1 |0 |0 | q1 | Push 0 |

| q1 |0 |1 | q1 | Pop 1 |

| q1 |1 |0 | q2 |- |

| q2 |1 |0 | q2 |- |

| q2 |ε |0 | q3 | Pop 0 |

Explanation:

- The NPDA starts at state q0 with an empty stack.

- When it encounters a '0', it pushes a '0' onto the stack.

- If the top of the stack is '0' when the NPDA encounters another '0', it pushes another '0' onto
the stack.

- If the top of the stack is '1' when the NPDA encounters a '0', it pops the '1' from the stack.

- If the NPDA encounters a '1' while the top of the stack is '0', it moves to state q2 without
modifying the stack.

- At the end of the input, if the top of the stack is '0' and the NPDA encounters an ε (empty
string), it moves to the final state q3 by popping the '0' from the stack.

- If at any point the NPDA reads an input symbol for which there is no transition defined in the
table, or the stack is empty before reaching the final state, the NPDA rejects the input.

Acceptance Criteria:

- The NPDA accepts the input if it reads all the input symbols, ends in state q3, and the stack is
empty.

- The NPDA rejects the input in all other cases.

Note: The NPDA described here assumes that the input contains only the symbols '0' and '1'. If
there are other symbols in the input, additional transitions and/or conditions need to be added
to the transition table.'1's.

You might also like