Lab 8 - NDFSA

Lab Session #8 #

Agenda #

  • Non-deterministic FSA
  • NDFSA to (D)FSA
  • Regular Expressions (RegExp)

Non-deterministic Finite State Automata (NDFSA) #

Definition #

A NDFSA is a tuple Q,I,δ,q0,F \lang Q, I, \delta, q_0, F\rang , where Q,I,q0,FQ, I, q_0, F are defined as in (D)FSA and the transition function is defined as

δ:Q×IP(Q) \delta : Q \times I \to \mathbb{P}(Q)

P \mathbb{P} is the powerset function (i.e. set of all possible students)

A NDFSA modifies the definition of a FSA to permit transitions at each stage to either zero, one, or more than one states.


The extended transition δ* for NDFSA #

Let M=Q,I,δ,q0,F M = \lang Q, I, \delta, q_0, F\rang be a NDFSA. We define the extended transition function as follows:

  1. For every qQ q \in Q , δ(q,ϵ)={q} \delta^\ast(q,\epsilon) = \{q\}
  2. For every qQ q \in Q , every yI y \in I^\ast , and every iI i \in I ,
δ(q,yi)=qδ(q,y)δ(q,i) \delta^\ast(q,yi) = \bigcup_{q'\in\delta^\ast(q,y)}\delta(q',i)

Acceptance by a NDFSA #

Let M=Q,I,δ,q0,F M = \lang Q, I, \delta, q_0, F\rang be a NDFSA. and let xI x \in I^\ast . The string x x is accepted by M M if

δ(q0,x)F \delta^\ast(q_0,x)\cap F \neq \varnothing

and it is rejected by M M otherwise.

Notion: Among the various possible runs (with the same input) of the NDFSA, it is sufficient that one of them succeeds to accept the input string.


Exercises on NDFSA #

Build NDFSAs that recognise the following languages:

  • La={x{0,1}x L_a = \{x \in \{0, 1\}^* \mid x ends with 101}101\} ;
  • Lb={xyx{a}y{a,b}y L_b = \{xy \mid x \in \{a\}^* \wedge y \in \{a, b\}^* \wedge y does not start with b\text{\textquoteleft}b\text{\textquoteright} \wedge every a\text{\textquoteleft} a \text{\textquoteright} in yy is followed by exactly one b}\text{\textquoteleft}b\text{\textquoteright}\} ;
  • La={x{a,b,c}x L_a = \{x \in \{a, b, c\}^* \mid x ends with either abab , bcbc or ca}ca\} ;

NDFSA to DFSA #

Algorithm for NDFSA to DFSA #

  1. Create state table from the given NDFA
  2. Create a blank state table under possible input alphabets for the equivalent DFA
  3. Mark the start state of the DFA by q0q_0 (Same as the NDFA)
  4. Find out the combination of States q0,q1,...,qnq_0, q_1, ..., q_n for each possible input alphabet
  5. Each time we generate a new DFA state under the input alphabet columns, we have to apply step 44 again, otherwise go to step 66
  6. The states which contain any of the accepting states of the NDFA are the accepting states of the equivalent DFA

Simple example (1) #

ex1

ex2


Example with steps #

Let us consider the following NDFSA:

NDFSA

First, we build a transition table for NDFSA:

Using table from previous step, let us create a similar table, but this time for FSA. Initially, the table is empty:

We begin by adding the initial state and the set of states:

The initial state can take us to two new states that are not yet in the table. Note that we treat a set of states as a single state now!

The next step is to find possible states for {q1,q2}\{q_1,q_2\} and q3q_3 . For q3q_3 it is trivial, you just need to look it up in the original NDFSA table. However, the transition for {q1,q2}\{q_1,q_2\} will be a union of sets: δ(q1,q2,0)=δ(q1,0)δ(q2,0)={q3}\delta({q_1,q_2},0) = \delta(q_1,0) \cup \delta(q_2,0) = \{q_3\} δ(q1,q2,1)=δ(q1,1)δ(q2,1)={q0,q1,q3}\delta({q_1,q_2},1) = \delta(q_1,1) \cup \delta(q_2,1) = \{q_0,q_1,q_3\}

Repeat the steps above until we have included all states from the original NDFSA and there are no new states.

After repeating previous steps and depicting final states we will arrive to the following table:

The result will be the following:


Exercise 1 #

Build DFSA from the NDFSA that recognizes the language:

L1={x{0,1}x L_1 = \{x \in \{0, 1\}^* \mid x ends with 101}101\} ;

sol1


Exercise 2 #

Build DFSA from the NDFSA that recognizes the language:

L2={xyx{a}y{a,b}y L_2 = \{xy \mid x \in \{a\}^* \wedge y \in \{a, b\}^* \wedge y does not start with b\text{\textquoteleft}b\text{\textquoteright} \wedge every a\text{\textquoteleft} a \text{\textquoteright} in yy is followed by exactly one b}\text{\textquoteleft}b\text{\textquoteright}\} ;

sol2


Exercise 3 #

Build DFSA from the NDFSA that recognizes the language:

L3={x{a,b,c}x L_3 = \{x \in \{a, b, c\}^* \mid x ends with either abab , bcbc or ca}ca\} ;

sol3


Regular Expressions (RegExp) #

Definition #

Inductive definition of RegExps over an alphabet Σ\Sigma : Basis.

  • Symbol \emptyset is a regular expression (denoting the langauge \emptyset );
  • Symbol ϵ\epsilon is a RegExp (denoting the language {ϵ}\{\epsilon\} );
  • Each symbol σ\sigma of Σ\Sigma is a RegExp

L(σ)={σ}L(\sigma) = \{\sigma\} for each σΣ\sigma\in\Sigma

Induction. Let rr and ss be two RegExps, then

  • (rs)(r\cdot{s}) is a RegExp (for simplicity, the dot is often omitted); L((rs))={ww(wL(r)wL(s))}L((r\cdot{s})) = \{ww'\mid(w \in L(r) \wedge w' \in L(s))\}
  • (rs)(r|s) is a RegExp L((rs))=L(r)L(s)L((r|s)) = L(r) \cup L(s)
  • rr^* is a RegExp L(r)=L(r)L(r^*) = L(r)^*

If AA and BB are RegExp, then

  • AB={xy|xAA\cdot{B} = \{xy\text{\textbar}x \in A and yB}y \in B\}
  • A|B={x|xAA\text{\textbar}B = \{x\text{\textbar}x \in A or xB}x \in B\}
  • A={x1x2x3...xk|k0A^* = \{x_1\cdot{x_2}\cdot{x_3}\cdot{...}\cdot{x_k}\text{\textbar}k\geq 0 and each xiA}x_i \in A\}

are also RegExp.

It is also possible to use the following notation:

A+={x1x2x3...xk|k1A^+ = \{x_1\cdot{x_2}\cdot{x_3}\cdot{...}\cdot{x_k}\text{\textbar}k\geq 1 and each xiA}x_i \in A\}

Exercises (1) #

Consider the alphabet Σ={0,1}\Sigma = \{0, 1\} . Give English descriptions of the languages of the following regular expressions.

  1. \emptyset ;
  2. \emptyset{^*} ;
  3. (01)000(0|1)(0 ^ \ast 1 ^ \ast )^\ast 000 ( 0 \text{\textbar} 1 )^\ast ;
  4. (1|ϵ)(001)0(1\text{\textbar}\epsilon)(00^\ast 1)^\ast 0^\ast ;

Exercises (2) #

Consider the alphabet Σ={a,b}\Sigma = \{a, b\} . Build Regular Expressions for: 5. The set of strings that consist of alternating aa ’s and bb ’s; 6. The set of strings that contain an odd number of aa ’s; 7. The set of strings that end with bb and do not contain the substring aaaa ; 8. The set of strngs in which both the number of aa ’s and the number of bb ’s are even.

Homework on NDFSA #

A. Construct NDFSAs over alphabets Σ1={a,b}\Sigma_1 = \{a, b\} and Σ2={0,1}\Sigma_2 = \{0, 1\}

  1. L0={xΣ2 L_0 = \{x \in \Sigma_2^\ast \mid any 00 in xx is followed by at least a 1}1\} .

Strings examplle: 010111010111 , 11111111 , 0111011101101110111011

  1. L1={xΣ1x L_1 = \{x \in \Sigma_1^\ast \mid x contains the substring abbaab}abbaab\} .

  2. L2={xΣ1x2 L_2 = \{x \in \Sigma_1^\ast \mid |x| \geq 2 \wedge final two symbols are the same }\} .

  3. L3={xΣ2x L_3 = \{x \in \Sigma_2^\ast \mid x contains exactly 55 zeros }\} .

B. Convert NDFSAs from part A to DFSAs applying the algorithm presented in the lab.