0% found this document useful (0 votes)
34 views6 pages

BCS503 TOC Third IA Test Scheme

Test questions

Uploaded by

Vasudev Shahapur
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)
34 views6 pages

BCS503 TOC Third IA Test Scheme

Test questions

Uploaded by

Vasudev Shahapur
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/ 6

USN

ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY


(An Autonomous Institution under VTU, Belagavi)
(Accredited by NAAC with A+ Grade, Accredited by NBA, New Delhi CSE &ECE)
Department of Computer Science & Engineering
Continuous Internal Evaluation Test III AY 2024-25
SCHEME OF VALUATION
Course Title: THEORY OF COMPUTATION Course Code: BCS503
Date: 17/12/2024 Time: 9.30 AM- 11.00 AM Semester/Section: V A, B, C
Faculty: Mr. Venkatesh, and Mrs. Merlyn Melita Mathias Max. Marks: 25
Note: Answer ONE FULL question from each PART.
Q. No. Questions Marks BTL COs POs
Part- A
1 a) Construct PDA to accept the language L= {wwR | w ∈ {a,b}*}. Draw the
graphical representation of this PDA. Organize the moves made by the 7 L3 3 1,2,3,9
PDA for the string aabbaa.
Ans Graphical representation of PDA:

------------------------→ 4 Marks
Moves made by the PDA for the string aabbaa ------------------------→ 3 Marks
(q0, aabbaa, Z0) ⊢ (q0, abbaa, aZ0)
⊢ (q0, bbaa, aaZ0)
⊢ (q0, baa, baaZ0)
⊢ (q1, baa, baaZ0)
⊢ (q1, aa, aaZ0)
⊢ (q1, a, aZ0)
⊢ (q1, €, Z0)
⊢ (q2, €, Z0)
b) What is ambiguous grammar? Test for the grammar given below is
ambiguous or not. 6 L4 3 1,2,3,9
S → iCtS |iCtSeS | a
C→b
Ans Definition-----------→ 1 mark
A context free grammar G = (V, T, P, S) is ambiguous if there is at-least one string w in T* for
which we can find two different parse trees, each with the root labelled S and the yield w
Identifying string and Drawing Parse tree -----------------→5 marks

Since there are two different parse trees for the string ibtibtaea, given grammar is ambiguous

OR
Page | 1
2 a) Convert the following CFG to PDA
S → aABB | aAA
A → aBB | a 7 L3 3 1,2,3,9
B → bBB | A
C→a
Ans Step 1: Check whether the grammar is in GNF. All productions except the production B->A is in
GNF. Convert this production to GNF form and the resultant production is
B-> bBB | aBB | a

The resultant grammar is --------------------------→ 2 Marks


S -> aABB | aAA
A -> aBB | a
B -> bBB | aBB | a
C -> a

Step 2: Without taking any input make the transition to state q1 and push the start symbol S on to
the stack and the resulting transition is -----------→ 1 Mark

$ (q0, €, Z0) = (q1, SZ0)

Step 3: Introduce the transition for all the productions as follows ---------→ 3 marks

Production transition
S -> aABB $ (q1, a, S) = (q1, ABB)
S -> aAA $ (q1, a, S) = (q1, AA)
A -> aBB $ (q1, a, A) = (q1, BB)
A -> a $ (q1, a, A) = (q1, €)
B -> bBB $ (q1, b, B) = (q1, BB)
B -> aBB $ (q1, a, B) = (q1, BB)
B -> a $ (q1, a, B) = (q1, €)
C -> a $ (q1, a, C) = (q1, €)

Step 4: finally in state q1 make a transition to final state with € as the input

$ (q1, €, Z0) = (qf, Z0) ----------------------→ 1 mark


b) Define Deterministic PDA. Examine whether the PDA for the language 6 L4 3 1,2,3,11
L = {anbn: n ≥ 1} is deterministic?
Ans Definition ---------------------- 2 marks
A PDA is said to be deterministic if and only if the following two conditions are met:

1) (q,a,X) has atmost one member for q in Q , a in ∑ and X in T


2) If (q,a,X) is not empty then (q, €,X) must be empty

Writing the transitions for the PDA and checking conditions 4 marks
In the language L ={anbn : n>=1},
The transitions are
$ (q0, a, Z0) = (q0, aZ0)
$ (q0, a, a) = (q0, aa)
$ (q0, b, a) = (q1, €)
$ (q1, b, a) = (q1, €)
$ (q1, €, Z0) = (q2, Z0)

Since there is at-most one member for each transition of form (q, a, X), condition 1 is satisfied
Since $ (q1, €, Z0) = (q2, Z0) is not empty, there are no other transitions on the actual input a and b when
the state is q1 and the top of the stack is Z0. Hence Condition 2 is satisfied

Given Language is deterministic


Part- B
3 a) Develop the Turing Machine to accept the language L = { anbncn | n ≥ 1 }.
Draw the Transition Diagram and show the moves made by the Turing 6 L3 4 1,2,3,4
Machine for the input string aabbcc.
Page | 2
Ans Transition Table:

----------------→ 2 Marks

---→ 2 Marks
Moves made by the TM for the input aabbcc:
q0 a a b b c c Ⱶ X q1 a b b c c Ⱶ X a q1 b b c c Ⱶ X a Y q2 b c c Ⱶ X a Y b q2 c c Ⱶ X a Y q3 b Z c Ⱶ X a q3 Y b Z c
Ⱶ X q3 a Y b Z c Ⱶ q3 X a Y b Z c Ⱶ X q0 a Y b Z c Ⱶ X X q1 Y b Z c Ⱶ X X Y q1 b Z c Ⱶ X X Y Y q2 Z c Ⱶ X X Y Y Z q2 c
Ⱶ X X Y Y q3 Z Z Ⱶ X X Y q3 Y Z Z Ⱶ X X q3 Y Y Z Z Ⱶ X q3 X Y Y Z Z Ⱶ X X q0 Y Y Z Z Ⱶ X X Y q4 Y Z Z Ⱶ X X Y Y Y q4 Z Z
Ⱶ X X Y Y Z q4 Z Ⱶ X X Y Y Z Z q4 Ⱶ X X Y Y Z Z q5
q5 is accepting state. Hence the string is accepted by Turing Machine.
-----------------------→ 2 Marks
b) Make use of Subroutine, Construct Turing Machine for
multiplication. 6 L3 4 1,2,3,9
Ans To multiply m and n, our Turing Machine will start with 0m10n on it tape, and ends
with 0mn on the tape. The outline of the strategy is:
a. The tape will have one non-blank string of the form 0i10n10kn for some k
b. In one step, we change a 0 in the first group to B and add n 0’s to the last group, giving
us a string of the form 0i-110n10(k+1)n.
c. As a result, we copy the group of n 0’s to the end m times, once each time we change a
0 in the first group to B. When the first group of 0’s is completely changed to blanks,
there will be mn 0’s in the last group.
d. The final step is to change the leading 10n1to blanks, and we are done.
Subroutine implements the step 2 above, copying the block of n zeros to the end.
Analysing the Process:
Assume m = 2, and n = 3, Perform Multiplication of 2 * 3 and get the result 6.
First represent both m and n with number of 1’s and load this string into tape separated
by a 0. Provide the enough number of Blanks (B’s) at the end of the string after inserting a
separator symbol 0 at the end of the string.
We represent the number 2 with two 1’s (that is 11) and 3 with three 1’s (that is 111). We
load infinite number of B’s in the tape after the string separated by a symbol 0.
The Tape status will be as shown below:
1 1 0 1 1 1 0 B B B B B B

Logic: For each 1’s in m, Replace B’s at the end of the string (110111, in this case) with
number of 1’s that is represented by m (111, in this case). Now, replace all 1’s and 0’s by B
until second 0 from the beginning.
Process:
Step 1: Replace first 1 in n by B, and go on move to right until we get first 1 in m. Call
subroutine copy. Transition Functions are:
Ꟙ(q0, 1) = (q1, B, R)
Ꟙ(q1, 1) = (q1, 1, R)
Ꟙ(q1, 0) = (q2, 0, R)
The resultant tape is
1 1 0 1 1 1 0 B B B B B B
B

Now, the control head pointer is pointing to first 1 in n


Page | 3
Step 2: Use Copy subroutine to replace m number of B’s with m number of 1’s
The operation of Copy subroutine is as follows:
Copy subroutine will start from q2. Control head pointer is at first 1 in n.
Sub routine steps are as shown below:
(i) Replace first 1 by Y and move on to right until first B after first 0 in n and
replace first B by 1
The transition functions are:
Ꟙ(q2, 1) = (q3, Y, R)
Ꟙ(q3, 1) = (q3, 1, R)
Ꟙ(q3, 0) = (q3, 1, R)
Ꟙ(q3, B) = (q4, 1, L)
The tape structure for fist iteration of this step in the subroutine is
1 1 0 1 1 1 0 B B B B B B
B Y 1

Now the control head pointer is pointing to first 0 after n.


(ii) Move on to left until we reach to Y. Once we get Y, then move to right. The
transition functions are:
Ꟙ(q4, 0) = (q4, 0, L)
Ꟙ(q4, 1) = (q4, 1, L)
Ꟙ(q4, Y) = (q2, Y, R)
Repeat the step (i) and (ii) until we get 0 in q2 state. If we get 0 in q2 state, then go
to step (iii). We get the tape as:
1 1 0 1 1 1 0 B B B B B B
B Y Y Y 1 1 1

(iii) Move to left. The transition function is:


Ꟙ(q2, 0) = (q5, 0, L)
(iv) Replace Y by 1, and move to left. Transition functions is:
Ꟙ(q5, Y) = (q5, 1, L)
1 1 0 1 1 1 0 B B B B B B
B Y Y Y 1 1 1
1
(iv) Repeat this step (iv) until we received 0 in state q5. The tape is:
1 1 0 1 1 1 0 B B B B B B
B Y Y Y 1 1 1
1 1 1

Step (v) once we get a 0 in state q5, move to left and return. The transition
function is:
Ꟙ(q5, 0) = (q5, 0, L)
In calling Module,
Step 3: We received B in q5. Move to right and change state to q0. Transition function
is:
Ꟙ(q5, B) = (q0, B, R)
Step 4: Repeat the step 2 and step 3 until we receive 0 in q0 state.
The resultant tape is:
1 1 0 1 1 1 0 B B B B B B
B B Y Y Y 1 1 1 1 1 1
1 1 1
Y Y Y
1 1 1

Step 5: Once we get 0 in q0, replace this 0 by B and move to right


and change state to q6. The transition function is:
Ꟙ(q0, 0) = (q6, B, R). The resultant tape is:
1 1 0 1 1 1 0 B B B B B B
B B B Y Y Y 1 1 1 1 1 1
1 1 1
Y Y Y
1 1 1

Page | 4
Step 6: Replace 1 by B and move to right. No change of state. Transition function is
Ꟙ(q6, 1) = (q6, B, R)
Repeat the step 6 until we reached to 0 in q6. The resultant tape is:
1 1 0 1 1 1 0 B B B B B B
B B B Y Y Y 1 1 1 1 1 1
1 1 1
Y Y Y
1 1 1
B B B
Step 7: Replace 0 by B. Terminate the process.The resultant tape is:
1 1 0 1 1 1 0 B B B B B B
B B B Y Y Y B 1 1 1 1 1 1
1 1 1
Y Y Y
1 1 1
B B B

The State Transition Diagram is:

State Transition Diagram for Subroutine Copy is

OR
4 a) Develop the TM for Binary Palindrome strings. Draw the Transition Diagram and
6 L3 4 1,2,3,9
show the moves made by the Turing Machine for the input string 01010
Ans
Ꟙ(q0, 0) = (q1, B, R) Ꟙ(q3, 0) = (q3, 0, L) Ꟙ(q0, B) = (qf, B, L) → Even Palindrome
Ꟙ(q1, 1) = (q1, 1, R) Ꟙ(q3, B) = (q0, B, R) Ꟙ(q2, B) = (qf, B, L) → Odd Palindrome
Ꟙ(q1, 0) = (q1, 0, R) Ꟙ(q0, 1) = (q4, B, R) Ꟙ(q5, B) = (qf, B, L) → Odd Palindrome
Ꟙ(q1, B) = (q2, B, L) Ꟙ(q4, 1) = (q4, 1, R)
Ꟙ(q2, 0) = (q3, B, L) Ꟙ(q4, 0) = (q4, 0, R)
Ꟙ(q2, 1) = (q3, B, L) Ꟙ(q4, B) = (q5, B, L)
Ꟙ(q3, 1) = (q3, 1, L) Ꟙ(q5, 0) = (q3, B, L)
--------------------------→ 2 Marks
Write the State Transition Diagram:

--------------------------→ 2 Marks
Page | 5
Moves for the string: 01010
q0 0 1 0 1 0 Ⱶ B q 1 1 0 1 0 Ⱶ B 1 q 1 0 1 0 Ⱶ B 1 0 q 1 1 0 Ⱶ B 1 0 1 q 1 0 Ⱶ B 1 0 1 0 q 1
Ⱶ B 1 0 1 q 2 0 Ⱶ B 1 0 q 3 1 B Ⱶ B 1 q 3 0 1 B Ⱶ B q 3 1 0 1 B Ⱶ q3 B 1 0 1 B Ⱶ B q 0 1 0 1 B
Ⱶ B B q1 0 1 B Ⱶ B B 0 q1 1 B Ⱶ B B 0 1 q1 B Ⱶ B B 0 q2 1 B Ⱶ B B q3 0 B B Ⱶ B q 3 B 0 B B
Ⱶ B B q0 0 B B Ⱶ B B B q1 B B Ⱶ B B q2 B B B Ⱶ B qf B B B B
Since the qf is the final state.
--------------------------→ 2 Marks
b) Develop the transition functions of Multiple Tracks TM for
6 L3 4 1,2,3,9
Palindrome strings
Ans The transition function is defined by the following rules in which a and b, each may
stand for either 0 or 1.
• Ꟙ([q0, B], [B, a]) = ([q1, a], [*, a], R). In the initial state, M picks up the symbol a
(either 0, or 1), stores it in its finite control, goes to control state q1, “checks off”
the symbol it just scanned, and moves right. Changing the first components of
the tape symbol from B to *, it performs the check off.
• Ꟙ([q1, a], [B, b]) = ([q1, a], [B, b], R). M moves right, looking for the symbols, a
Blank, or a checked symbol. The symbols a and b, each can be either 0, or 1
• Ꟙ([q1, a], [B, B]) = ([q2, a], [B, b], L). When M finds the Blank, it moves to the left
and changes to the state q2
• Ꟙ([q2, a], [B, a]) = ([q3, B], [*, a], L). In state q2, M must make a decision, depending
on whether the symbol it is scanning is checked or unchecked. If unchecked, it
verifies whether the symbol is same as the one in its finite control. M then checks
off the symbol, because it has matched the corresponding symbol from the left
end of the input, goes to control state q3, dropping the symbol from its finite
control and continues moving left.
• Ꟙ([q3, a], [B, b]) = ([q3, a], [B, b], L). M moves left over unchecked symbols looking
for a checked one.
• Ꟙ([q3, b], [*, a]) = ([q0, B], [*, a], R). When M encounters a checked symbol, it moves
right and restarts the cycle changing back to state q0.
• Ꟙ([q1, a], [*, b]) = ([q2, a], [*, b], L). This is similar to step 3 for checked symbols
• Ꟙ([q2, a], [*, b]) = ([q4, B], [*, b], L). This branch covers the case in the state q2,
where the symbol being scanned is checked. M goes to state q4 and accepts.
• Ꟙ([q0, B], [*, b]) = ([q4, B], [*, b], R). Let us pick the branch from the state q0 where
we have just started moving right and find a checked symbol. M goes to state q4
and accepts.

Subject Handling Faculty Member Signature of the HOD

Page | 6

You might also like