Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Regular Languages

Regular language:
a Language recognized (Accepted) by some Finite Automata (FA)

Finite Automata (FA) = Finite State Machine (Models of Computer)

FA=∑States +∑ Rules for going from State1State2,


depending on the input Symbol.

2019-2020 Dr. Akram Massouh 1


Finite Automata (FA)
Deterministic Finite Automata (DFA)

• good models for computers with limited memory


• No Temporary Memory

DFA: FA in which, Every State has exactly one transition for


each input Symbol.

We can define the DFA informally (using the state Diagram) or


formally (by defining each item or group).

2019-2020 Dr. Akram Massouh 2


Deterministic Finite Automata DFA
Informal Definition of DFA ( State Diagram):
• a state diagram is used to model the dynamic behavior of a machine
in response to Input Symbols.
• Elements of state diagram
• State: A state represents the state of a machine at a particular
given point of time.it is represented by a circle (containing the
name of the state). Exp.

• Initial (Start) State: This state shows the first state of the
machine. It's marked by an arrow that goes into the state. Exp.

• Transition: The transition from one state to another state of a


machine is represented by an arrow. The transition is labeled
with the Input Symbol that triggered it and the action that
results from it. A state can have a transition that points back to
itself. Exp.

2019-2020 Dr. Akram Massouh 3


Deterministic Finite Automata DFA
Informal Definition of DFA ( State Diagram):

• Final (Accept) State: a special kind of state signifying that


the completed input symbols are accepted by the machine.

Example:

• This machine contains 2 states q1 and q2, q1 is the start state, q2 is the final state.
• Input Alphabet ( Symbols) is the set ∑={0,1}.
• At beginning, the machine is in state q1 and if symbol 0 enters, it moves to state q1, but if symbol
1 enters, it moves to state q2, etc.

2019-2020 Dr. Akram Massouh 4


Deterministic Finite Automata DFA

Formal Definition of DFA:


DFA is a 5-tuple, M=(Q, ∑, δ, q0, F) :
Q: Finite Set of States , example Q={q0,q1,q2}
∑: Input Alphabet ( Symbols), example: ∑={0,1}
δ: Q∑Q: Rules for moving (Transition Function)
δ(current state, input symbol)=next state

q0Q: Start (initial) State


FQ: Accept (Final) States Set

2019-2020 Dr. Akram Massouh 5


Deterministic Finite Automata DFA
Example:
The definition of the machine M accepts any word from the alphabet {0, 1}
ending with symbol 1 in both formal definition and informal definition equivalently.

We say that the M machine accepts the Language L and we denote it with L(M):

2019-2020 Dr. Akram Massouh 6


Deterministic Finite Automata DFA
If A= {All Strings that M accepts} , then
Language of machine ML(M)=A, or
M recognizes (accepts) A L(M)=A

M may accept several strings, but


it always recognizes only one Language.
In the example,
L(M) = {w: w ends in a 1}

2019-2020 Dr. Akram Massouh 7


Deterministic Finite Automata DFA
Example: DFA M=( Q, ∑, δ, q1, F)

Or 

L(M) = {w: w contains at least one 1 followed by an even number of 0's or 01.}

2019-2020 Dr. Akram Massouh 8


Deterministic Finite Automata DFA

Example: DFA M=( Q, ∑, δ, q1, F)

Homework: write the formal Definition of the DFA .

2019-2020 Dr. Akram Massouh 9


Designing DFA
Let: ∑={0,1} L(M)={All strings with an Odd numbers of 1's}

Design M :
1. Determine the necessary information (States)
2. Represent this information as finite list of States (even/odd).
3. Set the accept states
4. Set the start state ( for 0 symbols/ empty string)
5. Assign the Base transitions:
6. Set transition for each symbol

2019-2020 Dr. Akram Massouh 10


Designing DFA
Let: ∑={0,1}
L(M)={All strings that contain the string 001 as a substring}
examples: 0010, 1001, 001, 1111001111 (in the Language)
11, 0000 ( not in the language)
Design M :
1. States & Accept states & start state (as Base Transition):
if 0 (first) remember- 0 (second) remember- 1(third) :Success

2. Set transition for each symbol:

2019-2020 Dr. Akram Massouh 11


The Regular Operations

• Operations on a Language
Used to study properties of the regular languages.

• Definition: let A and B be Languages,


we get a new language by:

Star(Kleene closure): A*={x1x2..xk: k0 and xiA},

Concatenation( . Or ): A.B=AB={xy: xA and yB}

Union (+ Or ): A+B=AB={x: xA or xB}

2019-2020 Dr. Akram Massouh 12


The Regular Operations
Example:
Let ∑={a,..,z}, A={good, bad}, B={boy, girl}

A*={, good, bad, goodbad,goodgood, badbad,


goodgoodgood,…}
AB={good, bad, boy, girl}
AB={goodboy, badboy, goodgirl, badgirl}
BA ={boygood, boybad, girlgood, girlbad}

2019-2020 Dr. Akram Massouh 13


Non-Deterministic Finite Automata NFA & -NFA
In DFA:
Every State has exactly one transition for each Symbol of .
Labels are Symbols of .
May have locked dead states for unaccepted strings.

In NFA( or extended NFA -NFA):


Every State may has zero, one, or more transitions for
each Symbol of =   {  }.
Labels are Symbols of .
No need locked dead states.

2019-2020 Dr. Akram Massouh 14


Non-Deterministic Finite Automata NFA
Formal definition of NFA
NFA is a 5-tuple, N=(Q, ∑, δ, q0, F):
Q : Finite Set of States
∑ : Input Alphabet
δ: Q∑2Q [P(Q)] : Transition Function
q0Q : Start State.
FQ : Accept (Final) States Set

2019-2020 Dr. Akram Massouh 15


Non-Deterministic Finite Automata NFA
Example: NFA N=( Q, ∑, δ, q1, F)

L(N)= {all strings over {0,1} containing a 1 in the third position from the end }
(e.g.,000100 is in A but 0011 is not).

2019-2020 Dr. Akram Massouh 16


Non-Deterministic Finite Automata -NFA
Formal definition of -NFA
NFA is a 5-tuple, N=(Q, ∑, δ, q0, F):
Q : Finite Set of States
∑ : Input Alphabet
δ: Q ∑ 2Q [P(Q)] : Transition Function
q0Q : Start State.
FQ : Accept (Final) States Set

2019-2020 Dr. Akram Massouh 17


Non-Deterministic Finite Automata -NFA
Example: NFA N=( Q, ∑, δ, q1, F)

2019-2020 Dr. Akram Massouh 18


Non-Deterministic Finite Automata NFA
How does NFA Compute?

The NFA accepts if at least one of the computation branches


ends in an accept state.

2019-2020 Dr. Akram Massouh 19


Non-Deterministic Finite Automata NFA
Example

The input: 010110

2019-2020 Dr. Akram Massouh 20


Equivalence of NFA & DFA
Theorem: Every NFA has DFA.

• Language A is a regular if and Only if some NFA recognizes it.

• NFA & DFA: recognize the same class of Languages.

• NFA: more power - recognizes more Languages, Easer than DFA.

2019-2020 Dr. Akram Massouh 21


Equivalence of NFA & DFA
Constructing a DFA that is equivalent to NFA

1. QD = {All Subsets of QN}


2. ∑D = ∑N
3. SD = E(SN )
4. FD ={ All subsets containing any FN }
5. δD

6. Simplifying: Delete Every State without Input Arrows.

2019-2020 Dr. Akram Massouh 22


Equivalence of NFA & DFA
Example: NFA N=( Q, ∑, δ, q1, F)

L(N)={w: w{0,1}*ends with 01}

QN={q0,q1,q2}, N={0,1}, SN =q0, FN={q2}


QD={,{q0}, {q1}, {q2}, {q0,q1}, {q0,q2}, {q1,q2}, {q0,q1,q2}}
SD=E(q0)={q0}
FD={ {q2}, {q0,q2}, {q1,q2}, {q0,q1,q2}}

Homework: write the table of the transition function δD , and


draw the state diagram of the equivalent DFA.

2019-2020 Dr. Akram Massouh 23

You might also like