Temp Theory of Computation Assign 2
Temp Theory of Computation Assign 2
Draft
Roll no :
CS20B1012
CS20B1037
CS20B1064
CS20B1068
CS20B1094
CS20B1125
CS20B1127
1. (3 marks) A Model is a representative of a system under study. Models give
abstraction and many models (FA,PDA,TM) exist in computer science to model
problems that arise in various CS domains, the popular domains are computer
networks, computer organization, operating systems, big-data anal-ysis, etc.,
Case Study: High level Data link control protocol uses bit stuffing technique for
each data transfer. i.e., bits 11 is stuffed as prefix and suffix with every frame.
Frame contains data and CRC. For example, to transmit a frame 1101 with CRC
bits 10, HDLC actually transmits 1111011011. Receiver is synchronized to this
scheme so that when the data reaches the receiver the prefix and suffix are
removed and the data part is taken for CRC verification. Model the above scenario
using a deterministic finite automaton. i.e., the set of all finite strings over {0,1}
beginning with 11 and ending with 11.
DFA:
● Q = {q0,q1,q2,q3,q4,q5,q6,q7}
● Σ = {0,1}
● ઠ (see below)
● start state = q0
● F = {q6}
ઠ:
● ઠ(q0,0) = q7
● ઠ(q0,1) = q1
● ઠ(q1,0) = q7
● ઠ(q1,1) = q2
● ઠ(q2,0) = q2
● ઠ(q2,1) = q3
● ઠ(q3,0) = q4
● ઠ(q3,1) = q3
● ઠ(q4,0) = q2
● ઠ(q4,1) = q5
● ઠ(q5,0) = q2
● ઠ(q5,1) = q6
● ઠ(q6,0) = q2
● ઠ(q6,1) = q3
● ઠ(q7,0) = q7
● ઠ(q7,1) = q7
Since we know the size of input is always going to be between 8 to 32 bits, a DFA of a
binary tree structure would be suitable for the above case since there will be finite
number of states.
The depth of the root in this binary tree structure is 0 and is the initial state of the
DFA as well. Number of states are also finite - (1+2+4+8+...232 = 233 - 1)
As the state’s parent’s parent being invoked due to bit 1 which is the VALID bit (third bit
from right) its four children will be final states for every “valid” subtree.
3. The following two DFA models find applications in Bioinformatics.
i) (3 marks) L = {x | x when interpreted as a binary string is a multiple of 5 }.
. x ∈ {0, 1}∗
ii) (3 marks) L = {x | each block of 3 contains at least two 0’s }. x ∈ {0, 1}∗
i)
For divisibility by 5 the binary string must leave a remainder 0 when divided by 5 and
there are 5 possible remainders when divided by 5 = {0,1,2,3,4}. So let us have 5 states
named q0,q1,q2,q3,q4 where the qi state indicates the remainder of the binary string
given when divided by 5. And thus having the final state as q0 we can say that the given
binary string is divisible by 5.
So for a binary string abcde… the remainder of that string by 5 is the sum of the
remainder of ( a*(2^n) % 5 + b*(2^(n-1)) % 5 + c*(2^(n-2)) % 5 +...) and taking the
remainder of the final number and recursing it till we get one of the 5 remaining
numbers. So in the above expression we are reading abcde… one by one and then
recursion as abcde… -> (a%5 state)bcde…. -> … and so on.
0 000 → (q0)0 0 q0
1 001 → (q0)1 1 q1
2 010 → (q1)0 2 q2
3 011 → (q1)1 3 q3
4 100 → (q2)0 4 q4
With all the states in hand we shall continue till we have all ઠ relations in hand
5 101 → (q2)1 0 q0
6 110 → (q3)0 1 q1
7 111 → (q3)1 2 q2
8 1000→ (q4)0 3 q3
9 1001 → (q4)1 4 q4
ઠ:
● ઠ(q0,0) = q0
● ઠ(q0,1) = q1
● ઠ(q1,0) = q2
● ઠ(q1,1) = q3
● ઠ(q2,0) = q4
● ઠ(q2,1) = q0
● ઠ(q3,0) = q1
● ઠ(q3,1) = q2S
● ઠ(q4,0) = q3
● ઠ(q4,1) = q4
F = {q0}
Σ = {0,1}
Initial state = q0
Q = {q0,q1,q2,q3,q4}
Here q2 acts as a garbage collector. Whenever there is a block which does not have at
least two 0s (that is→ when it reads two 1s) then it goes to q2 and stays there for the
rest of the reading of inputs.
Here the initial state is q0 and the final states are q0,q1,q2,q3,q4,q5,q6,q7,q8. The
working of the above model is stated as: whenever the reader reads 1 the automaton
will move to its right state, else if it reads 0 then move to the left state.
The drawback of this automation is that this does not have finite number of states,
therefore not a FSA thus not a DFA (rather a Deterministic Infinite State Automaton).
To make a DFA such that |n0(s) − n1(s)| ≤ 4 is not possible because of the fact that
DFA or simple FSA cannot record nor store its previous states during the execution of
the automaton. That is, FSA cannot count the number of 1s and 0s since in a string ‘s’
there could be infinite 1s and 0s.
But the above model could work given that the string ‘s’ is less than a certain length,
thus giving us an idea of how many states we need.
String ‘s’ could have infinite length of 1s and 0s thus making the automaton not
finite therefore no DFA.
5. Let Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Consider the base 10 numbers formed by
strings from Σ∗
● Q = {q0,q1,q2,q3,q4,q5,q6,q7,q8,q9}
● Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
● ઠ (see below)
● start state = q0
● F = {q0,q5}
ઠ:
● ઠ(qi,j) = qj
○ i : 0 <= i <= 9
○ j : 0 <= j <= 9
○ i,j ∈ natural numbers
Therefore there are 100 transition states in the above model, here is the part of the
model:
ઠ:
A = {1,2,3,4,6,7,8,9}
B = {0,5}
● ઠ(q0,A) = q0
● ઠ(q0,B) = q1
● ઠ(q1,A) = q0
● ઠ(q1,B) = q1
Assignment 2:
1) (1+1+3=5 marks) L: the set of all finite strings over {0, 1} beginning with 11 and ending with
11. Write the regular expression. Construct an equivalent NFA (with epsilon). Use the DFA
constructed in Assignment 1 to obtain the Regular expression using Arden’s Theorem.
To find the regex of q4 (i.e. the final state - therefore language of the model in regex)
q0 = є → (i)
q1 = q0.1 → (ii)
q2 = q1.1 + q2.0 + q3.0 + q4.0 → (iii)
q3 = q2.1 → (iv)
q4 = q3.1 + q4.1 → q4 = (q3.1).1* → (v)
Let T = 0*1(00*1)*11*
Therefore:
q4 = 11.T.(0.T)*
And we know T ends with 11, q4’s regex is for the language over {0,1}* where it starts with ‘11’
and ends with ‘11’
2) (1+1+3=5 marks) L: the set of all finite strings over {0, 1} such that the third bit from the right
is 1. Write the regular expression. Construct an equivalent NFA (with epsilon). Use the DFA
constructed in Assignment 1 to obtain the Regular expression using Arden’s Theorem.
Regex: (0+1)*1(0+1)(0+1)
5)
There are three states therefore all possible transitions will be like:
1) Find a CFG for the language over {0, 1} consisting of those strings in which the ratio of
the number of 1’s to the number of 0’s is three to two. Also, design a PDA.
PDA:
δ(qi,0,Z0) = (q0,XXXZ0) // starting with 0
δ(q0,0,X) = (q0,XXXX) // already read 0 correspondence to above function
δ(q01,XX) = (q0, є) // popping when reading 1 w.r.t. Above statements
δ(q0,є,Z0) = (qf , Z0) // end of process | Qf = final state
δ(q0,є,X) = (q0 , X)
δ(qi,є,Z0) = (qf,Z0)
CFG:
S → 11100
S → 11010
S → 10110
S → 01110
S → 11001
S → 10101
S → 01101
S → 10011
S → 01011
S → 00111
S → SS
S → 11100S
S → 1110S0
S → 111S00
S → 11S100
S → 1S1100
S → S11100
S → 11010S
S → 1101S0
S → 110S10
S → 11S010
S → 1S1010
S → S11010
S → 10110S
S → 1011S0
S → 101S10
S → 10S110
S → 1S0110
S → S10110
S → 01110S
S → 0111S0
S → 011S10
S → 01S110
S → 0S1110
S → S01110
S → 11001S
S → 1100S1
S → 110S01
S → 11S001
S → 1S1001
S → S11001
S → 10101S
S → 1010S1
S → 101S01
S → 10S101
S → 1S0101
S → S10101
S → 01101S
S → 0110S1
S → 011S01
S → 01S101
S → 0S1101
S → S01101
S → 10011S
S → 1001S1
S → 100S11
S → 10S011
S → 1S0011
S → S10011
S → 01011S
S → 0101S1
S → 010S11
S → 01S011
S → 0S1011
S → S01011
S → 00111S
S → 0011S1
S → 001S11
S → 00S111
S → 0S0111
S → S00111
ε statements:
A→ε
B→ε
S → ABA / BA/ AA / AB / A / B / ε
A → a / aA
B → b / bB // removed epsilon
S → ABA / BA/ AA / AB / a / aA / b / bB / ε
A → a / aA
B → b / bB // removed unit productions
CNF is not possible because ” S → ε “ is part of the grammar . Therefore, NO CNF EXISTS.
S → Sb / aSb / Sa / a
Derivation 1:
S → Sb | S → Sb
S → Sab | S → Sa
S → aab |S→a
Derivation 2:
S → aSb | S → aSb
S → aab |S→a
S → aS | aSbS | ε
Derivation 1:
S → aS | S → aS
S → aaSbS | S → aSbS
S → aaaSbSbS | S → aSbS
S → aaabSbS |S→ε
S → aaabbS |S→ε
S → aaabb |S→ε
Derivation 2:
S → aSbS | S → aSbS
S → aaSbS | S → aS
S → aaaSbSbS | S → aSbS
S → aaabSbS |S→ε
S → aaabbS |S→ε
S → aaabb |S→ε
Derivation :
S → aSS’ | S → aSS’
S → aaSS’S’ | S → aSS’
S → aaaSS’S’S’ | S → aSS’
S → aaaS’S’S’ |S→ε
S → aaaS’S’ | S’ → ε
S → aaabSS’ | S’ → bS
S → aaabS’ |S→ε
S → aaabbS | S’ → bS
S → aaabb | S’ → ε
CFG :
S → ab / abb / aSb / aSbb
PDA :
δ(q0,ε,Z0) = (q1,SZ0) // push ‘start’ symbol
// Non Deterministic PDA
δ(q1,ε,S) = (q1,aSb) // for S → aSb , push ‘aSb’
δ(q1,ε,S) = (q1,aSbb) // for S → aSb , push ‘aSbb’
δ(q1,ε,S) = (q1,ab) // for S → aSb , push ‘ab’
δ(q1,ε,S) = (q1,abb) // for S → aSb , push ‘abb’
∃∈
∝𝛼ɣβ
8) For the language of equal no of 0’s and 1’s, write the Greibach Normal Form.
CFG :
A1 → 0A11 / 1A10 / A101 / A110 / 01A1 / 10A1
A1 → 01 / 10
( Assume ‘ε’ is not a part of the language. If ‘ε’ is part of language CNF and GNF are not
possible. )
Then:
A1 → 0A1A3 / 1A1A2 / A1A2A3 / A1A3A2 / 0A3A1 / 1A2A1 / A2A3 / A3A2
A2 → 0
A3 → 1