0% found this document useful (0 votes)
31 views7 pages

Comp Sheet2B

Uploaded by

saalma.essaam
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)
31 views7 pages

Comp Sheet2B

Uploaded by

saalma.essaam
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/ 7

First Term, Academic Year

2024/2025 ‫ﺍﻻﺳﻡ‬
Theory of Computations
‫ﺍﻟﺭﻗﻡ‬
SHHET-2
‫ﺍﻟﺘﺨﺼﺺ‬

First: Choose the correct answer


Q.1 Which of the following is false?

(a) The languages accepted by FA's are regular languages.


(b) Every DFA is an NFA.
(c) There are some NFA's for which no DFA can be constructed.
(d) If L is accepted by an NFA with E transition then L is accepted by an NFA without ϵ transition.

Q.2 Which of the following are regular languages?

(i) The language {w| w ϵ {a, b}*, w has an odd number of b's}.
(ii) The language {w | w ϵ {a, b}*, w has an even number of b's}.
(iii) The language {w| w ϵ {a, b}*, w has an even number of b's and odd number of a's}.

(a) (i) and (ii) only (b) (i) only

(c) (ii) only (d) All of these

Q.3 How many minimum number of states are required in the DFA (over the alphabet {a, b}) accepting all the strings
with the number of a's divisible by 4 and number of b's divisible by 5?
(a) 20 (b) 9
(c) 7 (d) 15

Q.4 How many states does the DFA constructed for The set of all strings ending with "00", have?

(a) 2 (b) 3

(c) 4 (d) 5

Q.5 The transition function of DFA from one state to another on a given input symbol w is a function Q x Σ* to
(a) 2Q (b) Q
(c) Q' (d) Q2

Q.6 The basic limitation of FSM is that


(a) It can not remember arbitrary large amount of information.
(b) It sometimes fails to recognize grammars that are not regular
(c) It sometimes fails to recognize grammars that are regular.
(d) All of these

1
Q.7 Consider the machine M shown below:
a,b

a,b

L(M) = ?

(a) L(M) = {words starting with aa or bb}


(b) L(M) = {words ending with aa or bb}
(c) L(M) = {words containing aa or bb as a subword}
(d) None of these

Q.8 The FSM shown in the figure accepts

(a) All strings (b) No strings


(c) ϵ -alone (d) None of these

Q.9 The FSM shown in the figure accepts

(a) All strings (b) No strings

(c) ϵ -alone (d) None of these

Q.10 Consider the FA shown in the figure given below, where "-" is the start and "+" is the ending state. The language
accepted by the FA is

(a) (a+ b)*b ( b) (a+ b )*a


(c) a*b (d) a*b*

2
Theorem 5.9 Closure Properties of Büchi Automata
Theorem and Proof: The Büchi-acceptable languages (like the regular languages) are closed under:

• Concatenation with a regular language: if L1 is a regular language and L2 is a Büchi-acceptable language, then L1L2
is Büchi-acceptable. The proof is similar to the proof that the regular languages are closed under concatenation
except that, since  transitions are not allowed, the machines for the two languages must be “glued together”
differently. If q is a state in the FSM that accepts L1, and there is a transition from q, labeled c, to some accepting
state, then add a transition from q, labeled c, to each start state of the Büchi automaton that accepts L2.
• Union: if L1 and L2 are Büchi-acceptable, then L1  L2 is also Büchi-acceptable. The proof is analogous to the
proof that the regular languages are closed under union. Again, since  transitions are not allowed, we must use a
slightly different glue. The new machine we will build will have transitions directly from a new start state to the
states that the original machines can reach after reading one input character.
• Intersection: if L1 and L2 are Büchi-acceptable, then L1  L2 is also Büchi-acceptable. The proof is by construction
of a Büchi automaton that effectively runs a Büchi automaton for L1 in parallel with one for L2.
• Complement: if L is Büchi-acceptable, then L is also Büchi-acceptable. The proof of this claim is less obvious.
It is given in [Thomas 1990].

Further, if L is a regular language, then L is Büchi-acceptable. The proof is analogous to the proof that the regular
languages are closed under Kleene star, but we must again use the modification that was used above in the proof of
closure under concatenation.

Büchi automata are useful as models for computer systems whose properties we wish to reason about because a set of
important questions can be answered about them. In particular, Büchi automata share with FSMs the existence of
decision procedures for all of the properties described in the following theorem:

Theorem 5.10 Decision Procedures for Büchi Automata


Theorem: There exist decision procedures for all of the following properties:
• Emptiness: Given a Büchi automaton B, is L(B) empty?
• Nonemptiness: Given a Büchi automaton B, is L(B) nonempty?
• Inclusion: Given two Büchi automata B1 and B2, is L(B1)  L(B2)?
• Equivalence: Given two Büchi automata B1 and B2, is L(B1) = L(B2)?

Proof: The proof of each of these claims can be found in [Thomas 1990].

5.13 Exercises
1) Give a clear English description of the language accepted by the following DFSM:

1 b 2 a 3

a a b a a

4 b 5 6

a, b

Chapter 5 87 Finite State Machines


2) Show a DFSM to accept each of the following languages:
a) {w  {a, b}* : every a in w is immediately preceded and followed by b}.
b) {w  {a, b}* : w does not end in ba}.
c) {w  {0, 1}* : w corresponds to the binary encoding, without leading 0’s, of natural numbers that are evenly
divisible by 4}.
d) {w  {0, 1}* : w corresponds to the binary encoding, without leading 0’s, of natural numbers that are powers
of 4}.
e) {w  {0-9}* : w corresponds to the decimal encoding, without leading 0’s, of an odd natural number}.
f) {w  {0, 1}* : w has 001 as a substring}.
g) {w  {0, 1}* : w does not have 001 as a substring}.
h) {w  {a, b}* : w has bbab as a substring}.
i) {w  {a, b}* : w has neither ab nor bb as a substring}.
j) {w  {a, b}* : w has both aa and bb as substrings}.
k) {w  {a, b}* : w contains at least two b’s that are not immediately followed by an a}.
l) {w  {0, 1}* : w has no more than one pair of consecutive 0’s and no more than one pair of consecutive
1’s}.
m) {w  {0, 1}* : none of the prefixes of w ends in 0}.
n) {w {a, b}*: (#a(w) + 2#b(w)) 5 0}. (#aw is the number of a’s in w).

3) Consider the children’s game Rock, Paper, Scissors . We’ll say that the first player to win two rounds wins the
game. Call the two players A and B.
a) Define an alphabet  and describe a technique for encoding Rock, Paper, Scissors games as strings over .
(Hint: each symbol in  should correspond to an ordered pair that describes the simultaneous actions of A
and B.)
b) Let LRPS be the language of Rock, Paper, Scissors games, encoded as strings as described in part (a), that
correspond to wins for player A. Show a DFSM that accepts LRPS.

4) If M is a DFSM and   L(M), what simple property must be true of M?

5) Consider the following NDFSM M:

a
a
b

b
a
b

For each of the following strings w, determine whether w  L(M):


a) aabbba.
b) bab.
c) baba.

Chapter 5 88 Finite State Machines


6) Show a possibly nondeterministic FSM to accept each of the following languages:
a) {anbam : n, m  0, n 3 m}.
b) {w  {a, b}* : w contains at least one instance of aaba, bbb or ababa}.
c) {w  {0-9}* : w corresponds to the decimal encoding of a natural number whose encoding contains, as a
substring, the encoding of a natural number that is divisible by 3}.
d) {w  {0, 1}* : w contains both 101 and 010 as substrings}.
e) {w  {0, 1}* : w corresponds to the binary encoding of a positive integer that is divisible by 16 or is odd}.
f) {w  {a, b, c, d, e}* : |w|  2 and w begins and ends with the same symbol}.

7) Show an FSM (deterministic or nondeterministic) that accepts L = {w  {a, b, c}* : w contains at least one
substring that consists of three identical symbols in a row}. For example:
• The following strings are in L: aabbb, baacccbbb.
• The following strings are not in L: , aba, abababab, abcbcab.

8) Show a DFSM to accept each of the following languages. The point of this exercise is to see how much harder it
is to build a DFSM for tasks like these than it is to build an NDFSM. So do not simply build an NDFSM and
then convert it. But do, after you build a DFSM, build an equivalent NDFSM.
a) {w  {a,b}* : the fourth from the last character is a}.
b) {w  {a, b}* : x, y  {a,b}* : ((w = x abbaa y)  (w = x baba y))}.

9) For each of the following NDFSMs, use ndfsmtodfsm to construct an equivalent DFSM. Begin by showing the
value of eps(q) for each state q:
a)
1

q0  q1 0 q2

1  1  1

0
q3 0 q4 q5

b) a, b

q0 a q1 a, b q2 a, b q3 a, b q4

c) b
a
a
q0  q1 a q4

b  a a b
a

q3 b q2 b q5

Chapter 5 89 Finite State Machines


10) Let M be the following NDFSM. Construct (using ndfsmtodfsm), a DFSM that accepts L(M).

q1  q2 a q3

 b b

q4 q5

a
q6 q7
b b

11) For each of the following languages L:


(i) Describe the equivalence classes of L.
(ii) If the number of equivalence classes of L is finite, construct the minimal DFSM that accepts L.
a) {w  {0, 1}* : every 0 in w is immediately followed by the string 11}.
b) {w  {0, 1}* : w has either an odd number of 1’s and an odd number of 0’s or it has an even number of 1’s
and an even number of 0’s}.
c) {w  {a, b}* : w contains at least one occurrence of the string aababa}.
d) {wwR : w  {a, b}*}.
e) {w  {a, b}* : w contains at least one a and ends in at least two b’s}.
f) {w  {0, 1}* : there is no occurrence of the substring 000 in w}.

12) Let M be the following DFSM. Use minDFSM to minimize M.

a
q1 a q2 q3
a
b b b

b b
a
q4 a q5 q6
a

13) Construct a deterministic finite state transducer with input alphabet {a, b} for each of the following tasks:
a) On input w, produce 1n, where n = #a(w).
b) On input w, produce 1n, where n = #a(w)/2.
c) On input w, produce 1n, where n is the number of occurrences of the substring aba in w.

14) Construct a deterministic finite state transducer that could serve as the controller for an elevator. Clearly describe
the input and output alphabets, as well as the states and the transitions between them.

15) Consider the problem of counting the number of words in a text file that may contain letters plus any of the
following non-letter characters:

<blank> <linefeed> <end-of-file> , . ; : ? !

Chapter 5 90 Finite State Machines


Define a word to be a string of letters that is preceded by either the beginning of the file or some non-letter
character and that is followed by some non-letter character. For example, there are 11 words in the following
text:
The <blank> <blank> cat <blank> <linefeed>
saw <blank> the <blank> <blank> <blank> rat <linefeed>
<blank> with
<linefeed> a <blank> hat <linefeed>
on <blank> the <blank> <blank> mat <end-of-file>

Describe a very simple finite-state transducer that reads the characters in the file one at a time and solves the
word-counting problem. Assume that there exists an output symbol with the property that, every time it is
generated, an external counter gets incremented.

16) Real traffic light controllers are more complex than the one that we drew in Example 5.29.
a) Consider an intersection of two roads controlled by a set of four lights (one in each direction). Don’t worry
about allowing for a special left-turn signal. Design a controller for this four-light system.
b) As an emergency vehicle approaches an intersection, it should be able to send a signal that will cause the
light in its direction to turn green and the light in the cross direction to turn yellow and then red. Modify
your design to allow this.

17) Real bar code systems are more complex than the one that we sketched in Example
5.31. They must be able to encode all ten digits, for example. There are several
industry-standard formats for bar codes, including the common UPC code  found on
nearly everything we buy. Describe a finite state transducer that reads the bars and
outputs the corresponding decimal number.
0 12345 67890 5
18) Extend the description of the Soundex FSM that was started in Example 5.33 so that it can assign a code to the
name Pfifer. Remember that you must take into account the fact that every Soundex code is made up of exactly
four characters.

19) Consider the weather/passport HMM of Example 5.37. Trace the execution of the Viterbi and forward algorithms
to answer the following questions:
a) Suppose that the report ###L is received from Athens. What was the most likely weather during the time of
the report?
b) Is it more likely that ###L came from London or from Athens?

20) Construct a Büchi automaton to accept each of the following languages of infinite length strings:
a) {w  {a, b, c} : after any occurrence of an a there is eventually an occurrence of a b}.
b) {w  {a, b, c} : between any two a’s there is an odd number of b’s}.
c) {w  {a, b, c} : there never comes a time after which no b’s occur}.

21) In C 685, we describe the use of statecharts as a tool for building complex systems. A statechart is a hierarchically
structured transition network model. Statecharts aren’t the only tools that exploit this idea. Another is Simulink®
, which is one component of the larger programming environment Matlab ® . Use Simulink to build an FSM
simulator.

22) In C 696, we describe the Alternating Bit protocol for handling message transmission in a network. Use the FSM
that describes the sender to answer the question, “Is there any upper bound on the number of times a message
may be retransmitted?”

23) In C 717, we show an FSM model of a simple intrusion detection device that could be part of a building security
system. Extend the model to allow the system to have two zones that can be armed and disarmed independently
of each other.

Chapter 5 91 Finite State Machines

You might also like