Professional Documents
Culture Documents
№ 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
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.
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:
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:
-------------------------------
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
4.Construct an NFA with ∑ = {0, 1} that accepts all strings where the last character is 1.
State Q0:
State Q1:
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:
- 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:
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:
Note: The CFG assumes that the generated strings are formed only using the terminals 'a' and
'b'.
PDA Description:
- The PDA will use a single stack to keep track of the number of 'a's encountered.
Transition Table:
| q0 |a |- | q0 | Push a |
| q0 |a |a | q0 | Push a |
| q0 |b |a | q0 | Pop a |
| q0 |b |- | q1 |- |
Explanation:
- 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.
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:
| 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:
- 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).
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:
| q0 |a |- | q1, q2 | Push a |
| q2 |b |a | q1 | Pop a, Push b |
Explanation:
- 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.
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:
| 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:
- 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.
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.