06l1
TRANSCRIPT
-
8/13/2019 06L1
1/35
Formal Languages and Automata Theory 1
CSC 3130
Formal Languages and Automata Theory Lecturer
Evangeline Young (SHB 916, 26098401, [email protected] )
Guest lecturerProf. C.K. Cheng from UCSD
Lecture HourMon 4:30pm - 6:15pmFri 9:30am - 10:15am(In September, we will only meet once a week: Mon 4:30pm 6:30pm)
Tutorial Hours No tutorial in the first week
Text bookIntroduction to Automata Theory, Languages and Computation, 3 rd editionJohn E. Hopcroft, Rajeev Motwani and Jeffrey D. UllmanAddison Wesley
mailto:[email protected]:[email protected] -
8/13/2019 06L1
2/35
Formal Languages and Automata Theory 2
Formal Languages and Automata Theory
Planning ScheduleWeek 1-4 : Introduction, Finite Automata, Regular Expression
Different Kinds of FA, Properties of Regular Sets
Qui z 1 Week 5-8 : Context-Free Grammars, Normal Forms
Pushdown Automata, Properties of Context-Free LanguagesQui z 2
Week 9-12 : Turing Machines, UndecidabilityChomsky Hierarchy, LR(k) Grammars, Complexities
F inal Examin ation
(Chap. 2-4)
(Chap. 5-7)
(Chap. 8-10)
-
8/13/2019 06L1
3/35
Formal Languages and Automata Theory 3
Formal Languages and Automata Theory
Assessment Scheme Quiz 1 (12.5%) Quiz 2 (12.5%) Final Examination (40%) Homework (25%) Class Participation (10%)
Plagiarism in homework, quiz or examination will result in failing of thewhole course.
-
8/13/2019 06L1
4/35
Formal Languages and Automata Theory 4
Topics
Automata Theory
Grammars and Languages Complexities
-
8/13/2019 06L1
5/35
Formal Languages and Automata Theory 5
Why Automata Theory?
To study abstract computing devices which areclosely related to todays computers. A simple
example of finite state machine :
off onstart
1
1
There are many different kinds of machines.
-
8/13/2019 06L1
6/35
Formal Languages and Automata Theory 6
Another Example
start
0
1on
0
0
1
offoff
1
When will this be on?Try 100, 1001, 1000, 111, 00,
-
8/13/2019 06L1
7/35
Formal Languages and Automata Theory 7
Grammar and Languages
Grammars and languages are closely relatedto automata theory and are the basis ofmany important software components like: Compilers and interpreters Text editors and processors
Text searching System verification
-
8/13/2019 06L1
8/35
Formal Languages and Automata Theory 8
Complexities
Study the limits of computations. Whatkinds of problems can be solved with a
computer? What kinds of problems can besolved efficiently ?
Can you write a program in C that cancheck if another C program will terminate?
-
8/13/2019 06L1
9/35
Formal Languages and Automata Theory 9
Preliminaries
Alphabets Strings Languages Problems
-
8/13/2019 06L1
10/35
Formal Languages and Automata Theory 10
Alphabets
An alphabet is a finite set of symbols. Usually, use to represent an alphabet. Examples:
= {0,1}, the set of binary digits. = {a, b, , z}, the set of all lower -case letters. = {(, )}, the set of open and close parentheses.
-
8/13/2019 06L1
11/35
Formal Languages and Automata Theory 11
Strings
A string is a finite sequence of symbolsfrom an alphabet.
Examples: 0011 and 11 are strings from = {0,1} abc and bbb are strings from = {a, b, , z}
(()(())) and )(() are strings from = {(, )}
-
8/13/2019 06L1
12/35
Formal Languages and Automata Theory 12
Strings
Empty string : Length of string: |0010| = 4, |aa| = 2, | |=0 Prefix of string: aaabc, aaabc, aaabc Suffix of string: aaabc, aaabc, aaabc
Substring of string: aaabc, aaabc, aaabc
-
8/13/2019 06L1
13/35
Formal Languages and Automata Theory 13
Strings
Concatenation : =abd, =ce, =abdce Exponentiation : =abd, 3=abdabdabd, 0=
Reversal : =abd, R = dba k = set of all k-length strings formed by the
symbols in
e.g., ={a,b}, 2={ab, ba, aa, bb}, 0={ }What is 1? Is 1 different from ? How?
-
8/13/2019 06L1
14/35
Formal Languages and Automata Theory 14
Strings
Kleene Closure * = 0 1 2 = k 0 k e.g., ={a, b}, * = { , a, b, ab, aa, ba, bb, aaa,aab, abb, } is the set of all strings formed
by as and bs. + = 1 2 3 = k>0 k
i.e., * without the empty string.
-
8/13/2019 06L1
15/35
Formal Languages and Automata Theory 15
Languages A language is a set of strings over an alphabet. Examples:
={(, )}, L 1={(), )(, (())} is a language over . Theset L 2 of all strings with balanced left and right
parentheses is also a language over . ={a, b, c, , z}, the set L of all legal English
words is a language over . The set { } is a language over any alphabet.
What is the difference between and { }?
-
8/13/2019 06L1
16/35
Formal Languages and Automata Theory 16
Languages
Other Examples: ={0, 1}, L={0 n1n | n 1} is a language over
consisting of the strings {01, 0011, 000111, } ={0, 1}, L = {0 i1 j | j i 0} is a language over
consisting of the strings with some 0s (possiblynone) followed by at least as many 1s.
-
8/13/2019 06L1
17/35
-
8/13/2019 06L1
18/35
Formal Languages and Automata Theory 18
Finite Automata
( or Finite State Machines) This is the simplest kind of machine.
We will study 3 types of Finite Automata: Deterministic Finite Automata (DFA) Non-deterministic Finite Automata (NFA)
Finite Automata with -transitions ( -NFA)
-
8/13/2019 06L1
19/35
Formal Languages and Automata Theory 19
Deterministic Finite Automata
(DFA)We have seen a simple example before:
off onstart
1
1
There are some states and transitions (edges) between the states. The edge labels tell whenwe can move from one state to another.
-
8/13/2019 06L1
20/35
Formal Languages and Automata Theory 20
Definition of DFA
A DFA is a 5-tuple (Q, , , q0, F) where
Q is a finite set of states is a finite input alphabet is the transition function mapping Q to Q
q0 in Q is the initial state (only one)F Q is a set of final states (zero or more)
-
8/13/2019 06L1
21/35
Formal Languages and Automata Theory 21
Definition of DFAFor example:
off onstart
1
1
Q is the set of states: { on, off } is the set of input symbols: {1} is the transitions: off 1 on; on 1 off
q0 is the initial state: offF is the set of final states (double circle): { on}
-
8/13/2019 06L1
22/35
Formal Languages and Automata Theory 22
Definition of DFAAnother Example:
start
0
1q2
0
0
1
q1 q0
1
What are Q, , , q 0 and F in this DFA?
-
8/13/2019 06L1
23/35
Formal Languages and Automata Theory 23
Transition TableWe can also use a table to specify the transitions.
For the previous example, the DFA is (Q, , ,q0,F)where Q = {q 0,q1,q2}, = {0,1}, F = {q 2} and issuch that
StatesInputs
0 1q0
q1q2
q1 q0
q2 q0q1q0
Note that there is one transition only for each inputsymbol from each state.
-
8/13/2019 06L1
24/35
Formal Languages and Automata Theory 24
DFA ExampleConsider the DFA M=(Q, , ,q0,F) where Q ={q0,q1,q2,q3}, = {0,1}, F = {q 0} and is:
StatesInputs
0 1q0q1q2q3
q2
q2q1
q1q3
q3q0
q0
q0
q2 q3
q111
1
1
0 000
Start
We can use a transition table or a transition diagram to specifythe transitions. What input can take you to the final state in M?
OR
-
8/13/2019 06L1
25/35
Formal Languages and Automata Theory 25
Language of a DFA
Given a DFA M, the language accepted (orrecognized) by M is the set of all stringsthat, starting from the initial state, will reachone of the final states after the whole stringis read.
For example, the language accepted by the previous example is the set of all 0 and 1strings with even number of 0s and 1s.
-
8/13/2019 06L1
26/35
Formal Languages and Automata Theory 26
Class Discussion
Start q0 q1
Start q0 q1
Start q0 q1 q2
0 011
0 110
1 0
0 0,11
What are the languages accepted by these DFA?
-
8/13/2019 06L1
27/35
Formal Languages and Automata Theory 27
Class Discussion
Construct a DFA that accepts a language Lover = {0, 1} such that:(a) L contains 010 and 1 only. (b) L is the set of all strings ending with 101. (c) L is the set of all strings containing no
consecutive 1s nor consecutive 0s.
-
8/13/2019 06L1
28/35
Formal Languages and Automata Theory 28
Non-deterministic FA (NFA)
For each state, zero, one or more transitionsare allowed on the same input symbol.
An input is accepted if there is a pathleading to a final state.
-
8/13/2019 06L1
29/35
Formal Languages and Automata Theory 29
An Example of NFA
1
01
1
0Start
q0
q1
q2
In this NFA(Q, , ,q0,F), Q = {q 0,q1,q2}, = {0,1},F = {q 2} and is:
States Inputs0 1q0q1q2
{q1,q2}{q1 }{q
0}
{q2 }OR
Note that each transition can lead to a set of states,which can be empty.
-
8/13/2019 06L1
30/35
Formal Languages and Automata Theory 30
Language of an NFA
Given an NFA M, the language recognized byM is the set of all strings that, starting fromthe initial state, has at least one path reaching
a final state after the whole string is read.Consider the previous example:
For input 101, one path is q 0 q1 q1 q2 and theother one is q 0 q2 q0 q1. Since q 2 is a final state,so 101 is accepted. For input 1010, none of its
paths can reach a final state, so it is rejected.
-
8/13/2019 06L1
31/35
Formal Languages and Automata Theory 31
More Examples of NFA
q0 q1 q2a
b
b b
q0
q1
q2
q3
q4
q5
q6
q7
0-9
0-9
0-90-9
0-9
+,- +,-
E.
0-9 0-9 0-9
0-9 0-9
Start
Start
-
8/13/2019 06L1
32/35
Formal Languages and Automata Theory 32
Class Discussion
Consider the language L that consists of allthe strings over = {0, 1} such that the
third last symbol is a 1, (a) Construct a DFA for L.(b) Construct an NFA for L.
Is NFA more powerful than DFA?
-
8/13/2019 06L1
33/35
Formal Languages and Automata Theory 33
DFA and NFA
Is NFA more powerful than DFA? NO! NFA is equivalent to DFA.
DFA NFATrivial
ConstructiveProof
-
8/13/2019 06L1
34/35
Formal Languages and Automata Theory 34
Constructing DFA from NFAGiven any NFA M=(Q, , ,q0,F) recognizing alanguage L over , we can construct a DFA
N=(Q, , ,q 0,F) which also recognizes L: Q = set of all subsets of Q
e.g., if Q = {q 0, q1}, Q = {{ }, {q 0}, {q 1}, {q 0, q1}} q0 = {q 0}
F = set of all states in Q containing a final state of M ({q 1,q2, q i}, a) = (q1,a) (q2,a) ... (q i,a)
a state in N a state in N
-
8/13/2019 06L1
35/35
Formal Languages and Automata Theory 35
An Example of NFA DFAConsider a simple NFA:
Construct a corresponding DFA:
0
1
1Start
0 1
q0 q1
{q0}
{q0, q1}
{q1}
{}
Start 1
01
0
1,0 1,0