You are on page 1of 9

SULIT

FINAL EXAMINATION
SEMESTER I 2019/2020

CODE OF SUBJECT : SCSJ3203


NAME OF SUBJECT : Theory of Computer Science
YEAR / COURSE :
TIME : 3 hours
DATE :
VENUE :

INSTRUCTIONS TO THE STUDENTS:

ANSWER ALL 10 QUESTIONS IN THE QUESTION BOOKLET. THE


MARKS FOR EACH QUESTION IS AS INDICATED.

[Jawab semua soalan di dalam buku soalan yang diberikan. Markah setiap soalan
adalah seperti yang dinyatakan.]

Name

Identity card (or matric) Number:

Name of Lecturer

Subject Code SCSJ3203

This examination book consists of 9 printed pages including this page.


STRUCTURED QUESTIONS [100 marks]
Answer all the questions.

Question 1 [8 marks]

In each part below, write down three strings in the language generated by the expression,
one shortest string that NOT in the language and give short description of the language
using your own word.

(a) 0+(0 + 1)*1 (2 marks)

(b) (a(a + b)*b) + (b(a + b)*a) (2 marks)

(c) a*(baa*)*b* (2 marks)

(d) (0  10)*1(1  10)* (2 marks)

Question 2 [4 marks]

Consider the two regular expressions,

r = a* + b* s = ab* + ba* + b*a + (a*b)*

a) Find a string corresponding to r but not to s.

b) Find a string corresponding to s but not to r.

c) Find a string corresponding to both r and s.

d) Find a string in {a, b}* corresponding to neither r nor s.

2
Question 3 [10 marks]

In each of the following, draw a finite automata and define the regular expression accepting
the indicated language over {a, b}.

Description Finite Automata (FA) (2.5 marks x 4)


(a) The language of all strings that
begin or end with aa or bb

Regular Expression:

(b) The language of all strings


containing at least two a’s

Regular Expression:

(c) The language of all strings


containing both bb and aba as
substrings

Regular Expression:

(d) The language of all strings in


which the number of a’s is
even

Regular Expression:

3
Question 4 [10 marks]

Let M1 be a finite automata defined by


Q = {q0, q1, q2, q3, q4};  = {0, 1}; q0 = q0; F = {q3, q4};
δ:
δ 0 1
q0 q3 q1
q1 q1 q2
q2 q1 q1
q3 q4 q3
q4 - q4

(a) Give a state diagram for the formal definition given above. (2 marks)

(b) Is it NFA or DFA? ____________________ (1 mark)

(c) Trace the computation of 0011, 010001, 10010 (3 marks)

(d) Which of the strings in (c) are accepted by M1? (2 marks)

(e) Give a regular expression of the language accepted by M1. (2 marks)

4
Question 5 [10 marks]

Let M2 be a non deterministic finite automata defined by

M2 :

(a) Construct the transition table of M2.

(b) Trace all computations of the string aaabb in M2.

(c) Is aaabb in L(M)?

(d) Give a regular expression for L(M).

5
Question 6 [10 marks]

(a) The transition function of an automatic door controller, M3 can be described as follows:
NEITHER FRONT REAR BOTH
CLOSE CLOSE OPEN CLOSE CLOSE
OPEN CLOSE OPEN OPEN OPEN

NEITHER – no one is standing on either pad, FRONT – a person is standing on the pad in front of the
doorway, REAR – a person is standing on the pad to the rear of the doorway, BOTH – people are
standing on both pads
Draw a state diagram of an automatic door controller M3 as defined above. (3 marks)

(b) Design a state diagram of a canned drink vending machine, M4 that will determine the
combination of old and new Malaysian Ringgit; RM0.10, RM0.20, RM0.50 coins and
RM 1 note. The can drink selected should be dispensed at the total of RM1.

i) Define the states involved in your state diagram, M4. (2


marks)

ii) Define the initial state and final state. (1 mark)

iii) Describe the transition function of M4. (2


marks)

iv) Draw the finite automata of M4. (2


marks)

6
Question 7 [8 marks]

Let G be the grammar defined as:


G = ({S, B}, {a, b, c}, P, S)
P: S → aScc | B
B → bB | b
a) Give a set-theoretic definition of L(G). ______________________ (2 marks)

b) Construct a leftmost derivation of the string aabbcccc. (2 marks)

c) Build the derivation tree for the derivation from part (b). (2 marks)

d) Write 2 possible strings generated by G. ______________________ (2 marks)

Question 8 [10 marks]

Let M be the pushdown automata (PDA) defined as:


M = ({q0, q1, q2, q3, q4}, {a, b, c}, {A}, δ, q0, {q3})
δ: δ(q0, a, λ) = {[q0, A]}; δ(q2, b, λ) = {[q1, λ]};
δ(q0, λ, λ) = {[q1, λ]}; δ(q1, c, λ) = {[q3, λ]};
δ(q1, b, A) = {[q2, λ]}; δ(q3, c, λ) = {[q3, λ]}.

a) Give the state diagram for the PDA M1. (2 marks)

7
b) Trace computations of strings aabbbc, abbcc in M. (4 marks)

c) Give a set-theoretic definition of the language accepted by M. (2 marks)


____________________________________________

d) Write the shortest strings that are IN and NOT IN the language L(M),
besides . ______________________________________ (2 marks)

Question 9 [10 marks]

Let M be the PDA below:


(a,X) (b,X) (c,X/) (d,X)
(b,X) (c,X/) (d,X)
q0 q1 q2 q3

a) Give the transition table of M. (2 marks)

b) Trace computations of strings bbbccd in M. (2 marks)

c) Show that aabcdd  L(M), while bcd do not belong to L(M). (3 marks)

d) Give a set-theoretic definition of L(M). _____________________ (3 marks)

8
Question 10 [20 marks]

Consider the following PDAs. Match them with the suitable definition of the languages and grammars. Write your answer in the blank column of
the table below: (2 marks/each)

Matched
No Pushdown Automata Matched PDA (No.) Language PDA (No.) Grammar
(a,/X) (b,X/) (c,/)
S → aS | aA
A (b,X/) (c,/) {anbmcn | n > 0, m >= 0}
q0 q1 q2 A → bAc | λ

(a,/) (b,/A) (c,A/) S → AB


B (b,/A) (c,/)
n n m
{a b c | n, m > 0} A → aAb | 
q0 q1 q2 B → bBc | 
(a,/X) (b,X/) (b,/Y) (c,Y/)
S → aSc | aAc
C (,) (,) (,) {ambncn+1 | m >= 0, n > 0}
q0 q1 q2 q3 A → bA | λ

(a,/X) (b,/) (c,X/)


S → aSb | aAb
D (,/) (c,X/) {ambncn | n >= 0, m > 0}
q0 q1 q2 A → cA | c

(a,/) (b,/X) (c,X/) S → AB


E (,/) (,/)
m n+m n
{a b c | m, n  0} A → aA | 
q0 q1 q2 B → bBc | bcc

- END OF QUESTIONS -

You might also like