0% found this document useful (0 votes)
56 views

Computation Theory Lec

Uploaded by

Mahdi Last
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)
56 views

Computation Theory Lec

Uploaded by

Mahdi Last
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/ 36

Content

• Regular Languages

• Non-Regular Languages

• Finite Automata
STRINGS AND LANGUAGES
Review
An alphabet is a nonempty, finite set of objects
(symbols).
►Σ is usually used to indicate alphabets.
►For instance, Σ 1 = a, b, c, d, e, f , Σ 2 = 0, 1
A string over Σ is any finite sequence of symbols
from Σ.
The empty string ε (sometimes λ(lambda)) is
the string consisting of no symbols.
REGULAR LANGUAGE
A regular language is a language that can be
expressed with a regular expression or a deterministic
or non-deterministic finite automata or state machine. A
language is a set of strings which are made up of
characters from a specified alphabet, or set of
symbols. Regular languages are a subset of the set of
all strings. Regular languages are used in parsing and
designing programming languages and are one of the
first concepts taught in computability courses. These are
useful for helping computer scientists to recognize
patterns in data and group certain computational
problems together ,once they do that, they can take
similar approaches to solve the problems grouped
together.
NON-REGULAR LANGUAGES
WHAT IS NON-REGULAR LANGUAGE
A non-regular language refers to a type of
formal language that cannot be recognized
by a finite automaton or expressed using a
regular expression. In the context of the
chomsky hierarchy of formal languages, non-
regular languages fall above regular
languages in complexity.
Non-Regular Languages
Key Points:
1.Regular Languages are the simplest type of languages
and can be recognized by finite automata. They can be
defined using regular expressions and are closed under
operations like union, intersection, and complementation.
2.Non-Regular Languages are more complex and
require more powerful computational models, such as
pushdown automata or Turing machines. They cannot
be represented by finite automata alone because they
require memory or a stack to keep track of certain
patterns, such as matching nested parentheses.
REGULAR OPERATIONS

Example
Let A = good, bad and B = boy, girl
► A B: good, bad, boy, girl .
► A B: goodboy, badboy, goodgirl, badgirl .
► A : ε, good, bad, goodgood,goodbad, badgood, badbad, . . . .
► B : ε, boy, girl, boyboy,boygirl, girlboy, girlgirl, . . . .
Kleene's theorem

Kleene's theorem is used to show the


equivalence between regular languages,
regular expressions, and finite automata.
Kleene's theorem states that:
In simple words, a regular expression can
be used to represent a finite automaton
and vice versa.
Transition Graph
A Transition Graph is a diagrammatic representation of how an
automaton processes an input string. Specifically, it’s used to
visualize finite automata (NFA or DFA) and their states and
transitions between them.
Components of a Transition Graph:
1.States: Represented by circles. One of these states is the start
state, and one or more can be accepting (or final) states.
2.Transitions: Labeled arrows between states that describe how
the machine moves from one state to another based on input
symbols.
3.Start State: Denoted by an arrow pointing to it from nowhere.
4.Accept (Final) States: Denoted by a double circle.
5.Input Symbols: Labels on the arrows that specify which input
causes a transition from one state to another.
FINITE AUTOMATA (FA)

►A simple model of computation


►Read an input string from tape
►Determine if the input string is in
a language
►Determine if the answer for the
problem is “YES” or “NO” for the
given input on the tape
HOW DOES A FA WORK?

►At the beginning,


►the FA is in the start state (initial state)
►its tape head points at the first cell
►For each move, the FA
►reads the symbol under its tape head
►changes its state (according to the transition
function) to the next state determined by the
symbol read from the tape and its current
state
►move its tape head to the right one cell
HOW DOES A FA WORK?

►an FA stops
►when it reads all symbols on the tape
►Then, it gives an answer if the input
string is in the specific language:
►Answer “YES” if its last state is an
accept state
►Answer “NO” if its last state is not an
accept state
DETERMINISTIC FINITE AUTOMATA (INFORMAL)
► Regular languages can be defined using deterministic finite automata
(DFAs).
► Informally, a DFA M consists of a set of states q0, q1, . . . qn.
►q0 is called the start state.
►Some subset of q0, q1, . . . qn comprises the accept states.
► DFA M reads an input string w = w1 . . . wm, m 0:
► M operates in discrete steps.
► M occupies exactly one state at any given time.
►M begins in state q0.
► M reads w one character at a time, moving left to right.
► A transition function, together with the current state and character
determines M’s next state.
► If M reaches the end of w in an accept state, then M accepts string w.
Otherwise, it rejects it.
► The language L of M L(M) is the set of strings M accepts.
► A language is regular if and only if there is some DFA that accepts it.
STATE DIAGRAMS

Figure: An example DFA M1.

► A state diagram, a directed graph, is often used to represent DFAs.


► Nodes represent states.
► Nodes circled twice represent accept states.
► An edge with no starting node indicates the start state.
► Labelled edges represent the transition function.
► An edge qi −

a qj means that if M is in state qi and reads an a, it should
move to state qj .
Here, L(M1), the language of M1, is the set of strings that have at least
one 1, and the last 1 is followed by an even number of 0s.
DETERMINISTIC FINITE AUTOMATA (FORMAL)
Definition
► deterministic finite automaton (DFA) is a 5-tuple (Q, Σ, δ,q0, F):
► Q is a finite, nonempty set of states (cannot be empty).
► Σ input alphabet set(cannot be empty).
► δ : Q × Σ → Q is total function, the transition function.
►q0 ∈ Q is the start state (not more than one state and cannot be
empty).
► F ⊆ Q is the set of accept states (it can be zero or more).

► Observe that Q and Σ must be finite and nonempty.


► q0 must be in Q.
► δ is a total function and so maps every pair (q, a) of state q and symbol
a to some state q .
► F might be empty.
HOW CONSTRUCT
DETERMINISTIC FINITE AUTOMATA
Step1: define the language over alphabet .
Step2: construct DFA firstly with the smallest valid string
Step3: complete DFA

The below DFA can be formally defined as follows:


►Q = {q1, q2, q3}.
► Σ = {0, 1}. Language L={10,010,110,….}
► δ is given by the table:
δ 0 1
q1 q1 q2
q2 q3 q2
q3 q2 q2
►q0 = q1.
►F = {q2}
HOW CONSTRUCT
DETERMINISTIC FINITE AUTOMATA

RULE
While constructing a DFA,
•Always prefer to use the existing
path.
•Create a new path only when
there exists no path to go with
Why it is called
DETERMINISTIC FA
FA to be deterministic there are two rules :
1. Every state should response to all
of the inputs in the alphabet set.
2. q0 will never have the same
transition on the same input to a
different state .
Example 1:

Design a DFA over ∑ ={0, 1} that accepts


the only input a string “10”.
Solution:
In the above example, the language
contains only one string given below
L= {10}
DFA that accepts the only input a string
“10” is :
Example 1:
Example:2
Construct a DFA with ∑ = {a, b}
that accepts the only input “aaab”.
Solution:
The given question provides the
following language
L= {aaab}
The following diagram represents the
DFA accepter for L= {aaab}.
Example:2
Example:3
Construct DFA, which accept all the string over alphabets ∑
{0,1} that start with “0”.
Solution:
The given question provides the following language
L = {0, 01, 00, 010, 011, 000, 001,…, }
Let’s draw the DFA, which accepts all the strings starting
with “0”.
Example:3
Example:4
Construct DFA, which accept all the string over alphabets
∑ {a,b} that ending with ‘abb’ .
Solution:
All strings of the language ends with substring “abb”.
So, length of substring = 3.
Thus, Minimum number of states required in the DFA = 3
+ 1 = 4.
It suggests that minimized DFA will have 4 states.

Let L={abb,aabb,ababb,abbabb}
Example:4
NONDETERMINISTIC FINITE AUTOMATA (NFAS)

A Non Deterministic Finite Automaton is a


mathematical model of a system where one input
can result in a machine transitioning to multiple
different states simultaneously. Unlike a
Deterministic Finite Automaton (DFA) which
follows a single path for every distinct input, an
NDFA has several possible paths it can travel.
These potential paths create branches, leading to
the 'nondeterministic' behaviour.
NONDETERMINISTIC FINITE AUTOMATA

Non-Deterministic Finite Automata is defined by the


quintuple M = (Q, ∑, δ, q0, F)
Where:
•Q = finite set of states
•∑ = non-empty finite set of symbols called as input alphabets
•δ : Q x ∑ → 2Q is a total function called as transition function
•q0 ∈ Q is the initial state
•F ⊆ Q is a set of final states
NFA VERSUS DFA
• In a DFA, at every state q, for every symbol a, there is a unique
a-transition i.e. there is a unique q′ such that q a −→q′ . This is not
necessarily so in an NFA. At any state, an NFA may have multiple
a-transitions, or none.
• In a DFA, transition arrows are labelled by symbols from Σ; in an
NFA, they are labelled by symbols from Σ ∪ {}. I.e. an NFA may
have  -transitions.
• We may think of the non-determinism as a kind of parallel
computation wherein several processes can be running
concurrently. When the NFA splits to follow several choices, that
corresponds to a process “forking” into several children, each
proceeding separately. If at least one of these accepts, then the
entire computation accepts.
NONDETERMINISTIC FINITE AUTOMATA

The above NFA N1 can be formally defined as follows:


►Q = {q1, q2, q3, q4}.
► Σ = {0, 1}.
► δ is given by the table:
δ 0 1 ε
q1 {q1} {q1, q2}
q2 {q3 } {q3}
q3 {q4}
q4 {q4} {q4}
►q0 = q1.
►F = {q4}
NFA EXAMPLE 1:

Design an NFA with ∑ = {0, 1} for all binary


strings where the second last bit is 1.

Solution
The language generated by this example will include all
strings in which the second-last bit is 1.
L= {10, 010, 000010, 11, 101011……..}
The following NFA automaton machine accepts all
strings where the second last bit is 1
NFA EXAMPLE 1:

Where:
•{q0, q1, q2} refers to the set of states
•{0,1} refers to the set of input alphabets
•δ refers to the transition function
•q0 refers to the initial state
•{q2} refers to the set of final states

Transition Table for the δ 0 1

above Non- q0 q0 q0,q1


Deterministic Finite
q1 q2 q2
Automata is:
q2 – –
NFA EXAMPLE 2:
design an NFA with input alphabet ∑ = {0, 1} that accepts all
the strings that end with 01.
Solution
The language generated by this example will include
all strings that end with 01.
L= {01, 0101, 0000101, 101, 101001……..}
NFA EXAMPLE 2:

Transition Table for the above Non-Deterministic Finite


Automata is-
0 1
δ
q0 q0,q1 q0
q1 – q2
q2 – –
NFA Example 3 :

Construct an NFA with ∑ = {0, 1} in which each


string must contain “double ‘1’ is followed by
single ‘0’.

Solution
The language generated by this example will include
all strings that must contain “double ‘1’ is
followed by single ‘0’.
L= {110, 0110, 1110, 10100110……..}
NFA Example 3 :

Transition Table for the above Non-Deterministic Finite


Automata is-
0 1
δ
q0 q0 q0,q2
q1 – q2
q2 q3 –
q3 q3 q3
HOMEWORK
1. Design an NFA with ∑ = {0, 1} such that every
string includes the substring 1101.

2. Design an NFA with ∑ = {0, 1} such that every


string includes the substring 1101.

3. Construct DFA, which accepts all the strings over


alphabets ∑ {0,1} that ends with “0”.

4. Construct DFA, which accept all the string over


alphabets ∑ {0,1} where each string contains “00”.

You might also like