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

Lecture 3 - Finite Automata

The document is a lecture on Finite Automata, covering topics such as regular languages, their expressions, and examples of finite automata. It explains the structure of finite automata, including states, transitions, and the languages they accept. The lecture also includes exercises and solutions related to the construction of finite automata for various languages defined over the alphabet {a, b}.

Uploaded by

mszboy1083
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)
3 views

Lecture 3 - Finite Automata

The document is a lecture on Finite Automata, covering topics such as regular languages, their expressions, and examples of finite automata. It explains the structure of finite automata, including states, transitions, and the languages they accept. The lecture also includes exercises and solutions related to the construction of finite automata for various languages defined over the alphabet {a, b}.

Uploaded by

mszboy1083
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/ 37

THEORY OF AUTOMATA

Lecture 3 – Finite Automata


Lecturer: Zainab Iftikhar
National University of Technology (NUTECH), Islamabad
OUTLINE

• Previous Exercise Solutions


• Regular Languages
• Finite Automata
• Examples
EXERCISE SOLUTIONS

• Consider the language, defined over Σ = {𝑎, 𝑏} of words beginning with 𝒂 , then its regular
expression may be
𝑎(𝑎 + 𝑏)∗
• Consider the language, defined over Σ = {𝑎, 𝑏} of words beginning and ending in same letter,
then its regular expression may be
𝑎 + 𝑏 + 𝑎(𝑎 + 𝑏)∗ 𝑎 + 𝑏(𝑎 + 𝑏)∗ 𝑏
• Consider the language, defined over Σ = {𝑎, 𝑏} of words ending in 𝒃, then its regular expression may
be
(𝑎 + 𝑏)∗ 𝑏
• Consider the language, defined over Σ = {𝑎, 𝑏} of words not ending in a, then its regular expression
may be
𝑎 + 𝑏 ∗𝑏 + 𝜀
or
( 𝑎 + 𝑏 ∗ 𝑏)∗
LANGUAGES (RECAP)

• Everything in computing, including programs, inputs, outputs, protocols, is fundamentally a


sequence of symbols (i.e., a string).
• Languages help us formalize what computers can and cannot do.
• Every programming language has valid and invalid programs (strings of code).
• Every web URL has valid and invalid formats (a structured string).
• Every data format (JSON, XML) has rules on what sequences are allowed.
LANGUAGES

• Regular Language
• Recognized by finite automaton
• No memory (fixed number of states)
• Described by regular expressions

• Irregular language
• Cannot be recognized by finite automaton
• More powerful machines
• Requires memory (stack or tape)
• Described by context-free grammars
REGULAR LANGUAGES

The language generated by any regular expression is called a regular language.

• If 𝐿1 and 𝐿2 are regular languages, then following all languages are regular:
1) Union: 𝐿1 + 𝐿2 or 𝐿1 𝑈 𝐿2
2) Concatenation: 𝐿1𝐿2 or 𝐿2 𝐿1
3) Closure: 𝐿∗1
4) Reversal: 𝐿𝑅1 = 𝑤 𝑅 𝑤 ∈ 𝐿1 }

Note: All finite languages are regular


FINITE AUTOMATA

• Consider the following game board that contains 64 boxes


FINITE AUTOMATA

• There are some pieces of paper. Some are white in colour while others are black. The
number of pieces of paper are 64 or less. The possible arrangements under which these
pieces of paper can be placed in the boxes, are finite. To start the game, one of the
arrangements is supposed to be initial arrangement. There is a pair of dice that can generate
the numbers 2,3,4,…,12. For each number generated, a unique arrangement is associated
among the possible arrangements.
• It shows that the total number of transition rules of arrangement are finite. One and more
arrangements can be supposed to be the winning arrangement. It can be observed that the
winning of the game depends on the sequence in which the numbers are generated. This
structure of game can be considered to be a finite automaton.
FINITE AUTOMATA

• Defining language (Method 3): Finite Automata

• A Finite automaton (FA), is a collection of the followings


1) Finite number of states, having one initial and some (maybe none) final states.
2) Finite set of input letters (Σ) from which input strings are formed.
3) Finite set of transitions i.e. for each state and for each input letter there is a transition
showing how to move from one state to another.
FINITE AUTOMATA

• Let Σ = 𝑎, 𝑏 and States: 𝑥, 𝑦, 𝑧 where 𝑥 is an initial state and 𝑧 is final state.


• Transitions:
1) At state 𝑥 reading 𝑎, go to state 𝑧,
2) At state 𝑥 reading 𝑏, goes to state 𝑦,
3) At state 𝑦 reading 𝑎, 𝑏, go to state 𝑦,
4) At state 𝑧 reading 𝑎, 𝑏, go to state 𝑧
• These transitions can be expressed by the following table called transition table

Old States New States


Reading 𝑎 Reading 𝑏
𝑥 − 𝑧 𝑦
𝑦 𝑦 𝑦
𝑧 + 𝑧 𝑧
FINITE AUTOMATA

• It may be noted that the information of an FA, given in the previous table, can also be
depicted by the following diagram, called the transition diagram, of the given FA

a,b
Old States New States
y
Reading 𝑎 Reading 𝑏 b
𝑥 − 𝑧 𝑦
x-
𝑦 𝑦 𝑦 a a,b
𝑧 + 𝑧 𝑧
Z+

• This transition diagram is an FA accepting the language of strings, defined over Σ = {𝑎, 𝑏},
starting with a. It may be noted that this language may be expressed by the regular
expression: 𝑎 (𝑎 + 𝑏)∗
FINITE AUTOMATA

• To indicate the initial state, an arrow head can also be placed before that state and that the final state
with double circle, as shown below.
• Note: the labels of states are not necessary.

a, b

a, b
FINITE AUTOMATA

• Let Σ = {𝑎, 𝑏} and States: 𝑥, 𝑦, where 𝑥 is both initial and final state.
• Transitions:
• At state 𝑥 reading 𝑎 or 𝑏, go to state 𝑦.
• At state 𝑦 reading 𝑎 or 𝑏, go to state 𝑥.

Old States New States a, b


Reading Reading
a b x y
x± y y
y x x a, b

• This transition diagram is an FA accepting the language of strings, defined over Σ={a, b} of even
length. It may be noted that this language may be expressed by the regular expression:
( 𝑎 + 𝑏 𝑎 + 𝑏 )∗
FINITE AUTOMATA

• Construct an FA for the language L of strings, defined over Σ={a, b}, of odd length.

a,b

– +

a,b
FINITE AUTOMATA

• Consider the language 𝐿 of strings, defined over Σ = {𝑎, 𝑏}, starting with 𝒃.
• The language 𝐿 may be expressed by RE 𝑏(𝑎 + 𝑏)∗ , may be accepted by the following FA

a,b

––
b +

a,b
a
1
FINITE AUTOMATA

• It may be noted that corresponding to a given language there may be more than one FA accepting that
language, but for a given FA there is a unique language accepted by that FA.
FINITE AUTOMATA

• Consider the language 𝐿 of strings, defined over Σ = {𝑎, 𝑏}, ending in 𝑎. The language 𝐿 may be
expressed by RE: (𝑎 + 𝑏)∗ 𝑎
• This language may be accepted by the following FAs
a
b a a a
–– +

– +
a b
b
b

• Note: There may be another FA corresponding to the given language.


b
FINITE AUTOMATA

Consider two languages:


• 𝐿1 = The language of strings, defined over Σ = {𝑎, 𝑏}, beginning with 𝒂
• 𝐿2 = The language of strings, defined over Σ = {𝑎, 𝑏}, not beginning with 𝒃
Note: 𝜀 does not belong to 𝐿1 while it does belong to 𝐿2.
The language 𝐿1 may be expressed by the regular expression: 𝑎(𝑎 + 𝑏)∗

a,b

a
–– +

b a,b
FINITE AUTOMATA

• The language 𝐿2 may be expressed by the regular expression: 𝑎(𝑎 + 𝑏)∗ +𝜀

a,b

a
 +

a,b
b
FINITE AUTOMATA

• Consider the Language L of Strings of length two or more, defined over Σ = {𝑎, 𝑏}, beginning
with and ending in same letters.
The language 𝐿 may be expressed by the following regular expression
𝑎 (𝑎 + 𝑏)∗ 𝑎 + 𝑏 (𝑎 + 𝑏)∗ 𝑏
It is to be noted that if the condition on the length of string is not imposed in the above language, then
the strings 𝒂 and 𝒃 will then belong to the language.
This language 𝐿 may be accepted by the following FA

b a a

+
a b

a b
b
b
+
a
FINITE AUTOMATA

Construct an FA for the language L of strings, defined over Σ={a, b}, of odd length.
Solution:
The language L may be expressed by RE (a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b)
This language may be accepted by the following FA

a,b

1 – 2+

a,b
FINITE AUTOMATA

Construct an FA accepting the Language L of Strings, defined over Σ = {a, b}, beginning with and
ending in same letters.
Solution:
The language L may be expressed by the following regular expression
(a+b)+a(a + b)*a + b(a + b)*b
This language L may be accepted by the following FA
a a
b a
b 6+
2+ 4
a b
1– b a b
b
b a
3+ 5 7+
a
FINITE AUTOMATA

• Consider the language L of strings, defined over Σ = {a, b}. The language L may be expressed
by the following regular expression:
(a+b)*
• This language is accepted by the following FA:

a a,b

b
1 2
FINITE AUTOMATA

Consider the Language L of Strings , defined over Σ = {a, b}, beginning with and ending in different
letters.
The language L may be expressed by the following regular expression
a (a + b)* b + b (a + b)* a
This language may be accepted by the following FA

a b b

2 4+
a a
1–
b a
a
b
3 5+
b
FINITE AUTOMATA

Tasks:
• Consider the Language L , defined over Σ = {a, b} of all non empty strings.
• Construct an FA that does not accept any string.
• Consider the Language L of strings , defined over Σ = {a, b}, containing double a. (a+b)* (aa) (a+b)*.
FINITE AUTOMATA

Solutions: a,b

a,b
– +

a,b
a,b
– +

b a,b
a
a
1- 2 3+
b
FINITE AUTOMATA

Consider the language L of strings, defined over Σ={0, 1}, having double 0’s or double 1’s, The language
L may be expressed by the regular expression
(0+1)* (00 + 11) (0+1)*
This language may be accepted by the following FA
x

0 0
0,1

- 0 1 +

1
1

y
FINITE AUTOMATA

Consider the language L of strings, defined over Σ={a, b}, having triple a’s or triple b’s. The
language L may be expressed by RE
(a+b)* (aaa + bbb) (a+b)* a
2 4
This language may be accepted by the following FA

a
a b a,b

1–– a b 6+

b a
b

3 b 5
FINITE AUTOMATA

• Consider the EVEN-EVEN language, defined over Σ={a, b}. As discussed earlier that EVEN-
EVEN language can be expressed by the regular expression
(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*
EVEN-EVEN language may be accepted by the following FA b
1 3
b

a a a a

2 4
b
FINITE AUTOMATA a,b
y
Consider the language L = {𝜺, b, ab, bb}, defined over Σ ={a, b}, expressed by
𝜺 + b + ab + bb OR 𝜺 + b (𝜺 + a + b). a
a,b
The language L may be accepted by the following FA

1  a 3 b
4+
b
2+ b 5+

a,b
a
It is to be noted that the states x and y are called Dead States,
Waste Baskets or Davey John Lockers, as the moment one
enters these states there is no way to leave it.
x
a,b
FINITE AUTOMATA

• It is to be noted that to build an FA accepting the language having a smaller number of strings, the tree
structure may also help in this regard, which can be observed in the following transition diagram for the
Language L, discussed in the previous example

4
a

3 a,b
b
a a,b
5+ a,b
1± 8
a,b
b 6
a

2+ a,b
b
7+
FINITE AUTOMATA

Consider the language L = {aa, bab, aabb, bbba}, defined over Σ ={a, b}, expressed by
𝑎𝑎 + 𝑏𝑎𝑏 + 𝑎𝑎𝑏𝑏 + 𝑏𝑏𝑏𝑎
OR
𝑎𝑎 (ε + 𝑏𝑏) + 𝑏 (𝑎𝑏 + 𝑏𝑏𝑎)
The above language may be accepted by the following FA
a,b
x

b a,b
a a

1– a 2 a 3+
b 4 b 5+

b
6 b 7 b 8 a 9+
a
a b
10 a,b
a
b
11+ a,b y
a,b
FINITE AUTOMATA

Consider the language L = {w belongs to {a,b}*: length(w) >= 2 and w neither ends in aa nor bb}.
The language L may be expressed by the regular expression
(a+b)*(ab+ba)
This language may be accepted by the following FA

2
b 4+
a
a b
1– b a
b
b
3 a 5+
• Consider the language L = {w belongs to {a,b}*: w does not end in aa}.
The language L may be expressed by the regular expression
ε + 𝑎 + 𝑏 + (𝑎 + 𝑏)∗ (𝑎𝑏 + 𝑏𝑎 + 𝑏𝑏)
This language may be accepted by the following FA
a

aa
a

a b
b
a
ab

𝜀 b a

b ba
a
b
b a
b b

bb
EXERCISE

• Write a regular expression and construct an FA for a language of strings over Σ = 0,1
• Starting with 00 (e.g. 000, 001, 0010, 0011, …)
• Ending in 00 (e.g. 000, 100, 0100, 1100, …)
• Alternating in 0 and 1 (e.g. 01, 10, 010, 101, 0101, 1010, …)
• Write a regular expression and construct an FA for a language of strings over Σ = 𝑎, 𝑏
• Containing double 𝑎 or double 𝑏
• Containing no more than one 𝑏
• Even number of 𝑎 and odd number of 𝑏

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy