CS701 Solution 2

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Virtual University of Pakistan

Fall 2018

CS701 – Theory of Computation

Assignment 1

Instructions to Solve Assignments

The purpose of the assignments is to give students hands on practice. It is expected that
students will solve assignments themselves. Following rules will apply during the
evaluation of the assignment.

 Cheating from any source will result in zero marks in the assignment.
 Any student found cheating in any two of the assignments submitted during the
course will be awarded "F" grade in the course.
 No assignment after due date will be accepted.

1
Virtual University of Pakistan
Fall 2018

Answer the following questions in your own words. Plagiarism will be checked for
each question. Marks will be awarded on the basis of answer and plagiarism report.

Question 1 (10 Marks)


Give a regular expression for the following language, where Σ = {a, b}
{w | w has exactly two a’s and at least two b’s}

Solution:
There are six possible cases:
Three cases: both aa’s come in the start, end or middle
And the rest of three cases:
Hence the expression is:
aabbb* + bbb*aa + bb*aabb* + abbb*a + bb*abb*a + + abb*abb*

Question 2 (15 Marks)


Give a context-free grammar for the following language, where Σ = {a, b}
{w | the number of a’s is not equal to the number of b’s}

Solution:
The idea here is that either number of a’s is greater than the number of b’s or the number
of b’s and greater than the number of a’s.
S → TaT | RbR
T → TT | aTb | bTa | a | ɛ
R → RR | aRb | bRa | b | ɛ
Here T generates all strings with at least as many a’s as b’s and S → TaT forces an extra
a. Similarly, R generates all strings with at least as many b’s as a’s and S → RbR forces
an extra b.

Question 3 (15 Marks)


Following is a state diagram of a TM. q0 is the start state.

2
Virtual University of Pakistan
Fall 2018

Does the Turing machine accept the string abcc? Show the execution of the Turing
machine on the input by giving the sequence of configurations from the start to the
halting configuration.

Solution:

q0 abcc ⊢ a q1 bcc ⊢ ab q2 cc ⊢ abc q3 c ⊢ abcc q3 ⊢ abc q4 c


⊢ ab q4 cc ⊢ a q4 bcc ⊢ q4 abcc ⊢ q4 □abcc ⊢ q5 abcc ⊢ x q6 bcc ⊢ xb q6 cc
⊢ x q7 byc ⊢ q7 xbyc ⊢ x q8 byc ⊢ xx q6 yc ⊢ xxy q6 c ⊢ xx q7 yy ⊢ x q7 xyy
⊢ xx q8 yy ⊢ xxy q8 y ⊢ xxyy q8 ⊢ xxy q accept y

3
Virtual University of Pakistan
Fall 2018

Question 4 (10 Marks)


Let A = {4, 6, 8, 10, 12, 14 . . . .} (i.e. the set of even positive integers greater than 2).
Show that A is countable.

Solution:

We prove that A is countable by giving one-to-one correspondence with the set of natural
numbers N.

The mapping function f: N → A is: f(i) = 2(i) + 2

{1 2 3 4 5 …….}
↓ ↓ ↓ ↓ ↓
{4 6 8 10 12 …….}

You might also like