Download presentation
Presentation is loading. Please wait.
Published bySylvia Burke Modified over 8 years ago
1
Topic 3: Automata Theory 1
2
OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy. 2
3
What is Automata Theory? Study of abstract computing devices, or “machines” Automaton = an abstract computing device Note: A “device” need not even be a physical hardware! A fundamental question in computer science: Find out what different models of machines can do and cannot do The theory of computation Computability vs. Complexity 3
4
4 Alan Turing (1912-1954) Father of Modern Computer Science English mathematician Studied abstract machines called Turing machines even before computers existed Heard of the Turing test? (A pioneer of automata theory)
5
Languages & Grammars Languages: “A language is a collection of sentences of finite length all constructed from a finite alphabet of symbols” Grammars: “A grammar can be regarded as a device that enumerates the sentences of a language” - nothing more, nothing less N. Chomsky, Information and Control, Vol 2, 1959 5 Or “words” Image source: Nowak et al. Nature, vol 417, 2002
6
The Chomsky Hierachy 6 Regular (DFA) Context- free (PDA) Context- sensitive (LBA) Recursively- enumerable (TM) A containment hierarchy of classes of formal languages
7
The Central Concepts of Automata Theory 7
8
AlphabetAlphabet An alphabet is a finite, non-empty set of symbols We use the symbol ∑ (sigma) to denote an alphabet Examples: Binary: ∑ = {0,1} All lower case letters: ∑ = {a,b,c,..z} Alphanumeric: ∑ = {a-z, A-Z, 0-9} DNA molecule letters: ∑ = {a,c,g,t} … 8
9
StringsStrings A string or word is a finite sequence of symbols chosen from ∑ Empty string is (or “epsilon”) Length of a string w, denoted by “|w|”, is equal to the number of (non- ) characters in the string E.g., x = 010100 |x| = 6 x = 01 0 1 00 |x| = ? xy = concatentation of two strings x and y 9
10
LanguagesLanguages 10
11
The Membership Problem 11
12
12 LanguagesLanguages Let be a set of characters. is called the alphabet. A language over is set of strings of characters drawn from
13
13 Example of Languages Alphabet = English characters Language = English sentences Alphabet = ASCII Language = C++ programs, Java, C#
14
14 NotationNotation Languages are sets of strings (finite sequence of characters) Need some notation for specifying which sets we want
15
15 Regular Languages Each regular expression is a notation for a regular language (a set of words). If A is a regular expression, we write L(A) to refer to language denoted by A.
16
16 Regular Expression A regular expression (RE) is defined inductively aordinary character from the empty string
17
17 Regular Expression R|S= either R or S RS= R followed by S (concatenation) R*= concatenation of R zero or more times (R*= |R|RR|RRR...)
18
18 RE Extentions R?= | R (zero or one R) R + = RR* (one or more R) (R)= R (grouping)
19
19 RE Extentions [abc]= a|b|c (any of listed) [a-z]= a|b|....|z (range) [^ab]= c|d|... (anything but ‘a’‘b’)
20
20 Regular Expression REStrings in L(R) a “a” ab “ab” a|b “a” “b” (ab)* “” “ab” “abab”... (a| )b “ab” “b”
21
21 Example: integers integer: a non-empty string of digits digit = ‘0’|’1’|’2’|’3’|’4’| ’5’|’6’|’7’|’8’|’9’ integer= digit digit*
22
22 Example: identifiers identifier: string or letters or digits starting with a letter C identifier: [a-zA-Z_][a-zA-Z0-9_]*
23
23 RecapRecap Language L(R): set of strings represented by a regular expression R. L(R) is the language denoted by regular expression R.
24
24 How to Use REs We need mechanism to determine if an input string w belongs to L(R), the language denoted by regular expression R.
25
25 AcceptorAcceptor Such a mechanism is called an acceptor. input string language w L acceptor yes, if w L no, if w L
26
26 Finite Automata (FA) Specification: Regular Expressions Implementation: Finite Automata
27
27 Finite Automata Finite Automaton consists of An input alphabet ( A set of states A start (initial) state A set of transitions A set of accepting (final) states
28
28 Finite Automaton State Graphs A state The start state An accepting state
29
29 Finite Automaton State Graphs a A transition
30
30 Finite Automata A finite automaton accepts a string if we can follow transitions labelled with characters in the string from start state to some accepting state.
31
31 FA Example A FA that accepts only “1” 1
32
32 FA Example A FA that accepts any number of 1’s followed by a single 0 0 1
33
33 FA Example A FA that accepts ab*a Alphabet: {a,b} a b a
34
34 Table Encoding of FA Transition table a b a ab 01err 121 2 012
35
35 RE → Finite Automata Can we build a finite automaton for every regular expression? Yes, – build FA inductively based on the definition of Regular Expression
36
36 NFANFA Nondeterministic Finite Automaton (NFA) Can have multiple transitions for one input in a given state Can have - moves
37
37 Epsilon Moves ε – moves machine can move from state A to state B without consuming input A B
38
38 NFANFA operation of the automaton is not completely defined by input 1 1 0 On input “11”, automaton could be in either state ABC
39
39 Execution of FA A NFA can choose Whether to make -moves. Which of multiple transitions to take for a single input.
40
40 Acceptance of NFA NFA can get into multiple states Rule: NFA accepts if it can get in a final state 1 1 0 ABC 0
41
41 DFA and NFA Deterministic Finite Automata (DFA) One transition per input per state. No - moves
42
42 Execution of FA A DFA can take only one path through the state graph. Completely determined by input.
43
43 NFA vs DFA NFAs and DFAs recognize the same set of languages (regular languages) DFAs are easier to implement – table driven.
44
44 NFA vs DFA For a given language, the NFA can be simpler than the DFA. DFA can be exponentially larger than NFA.
45
45 NFA vs DFA NFAs are the key to automating RE → DFA construction.
46
46 RE → NFA Construction Thompson’s construction ( CACM 1968 ) Build an NFA for each RE term. Combine NFAs with -moves.
47
47 RE → NFA Construction Subset construction NFA → DFA Build the simulation. Minimize number of states in DFA (Hopcroft’s algorithm)
48
48 RE → NFA Construction Key idea: NFA pattern for each symbol and each operator. Join them with -moves in precedence order.
49
49 RE → NFA Construction s0s0 a s1s1 NFA for a s0s0 a s1s1 NFA for ab s3s3 b s4s4
50
50 RE → NFA Construction s0s0 a s1s1 NFA for a
51
51 RE → NFA Construction s0s0 a s1s1 NFA for a s3s3 b s4s4 NFA for b
52
52 RE → NFA Construction s0s0 a s1s1 NFA for a s0s0 a s1s1 s3s3 b s4s4 s3s3 b s4s4 NFA for b
53
53 RE → NFA Construction s0s0 a s1s1 NFA for a s0s0 a s1s1 NFA for ab s3s3 b s4s4 s3s3 b s4s4 NFA for b
54
54 RE → NFA Construction s0s0 s5s5 s1s1 a s2s2 NFA for a | b s3s3 b s4s4
55
55 RE → NFA Construction s1s1 a s2s2 NFA for a
56
56 RE → NFA Construction s1s1 a s2s2 s3s3 b s4s4 NFA for a and b
57
57 RE → NFA Construction s0s0 s5s5 s1s1 a s2s2 NFA for a | b s3s3 b s4s4
58
58 RE → NFA Construction s0s0 s4s4 s1s1 a s2s2 NFA for a*
59
59 RE → NFA Construction s1s1 a s2s2 NFA for a
60
60 RE → NFA Construction s0s0 s4s4 s1s1 a s2s2 NFA for a*
61
61 Example RE → NFA NFA for a ( b|c )* s3s3 s9s9 s4s4 s5s5 s6s6 s7s7 s8s8 s0s0 s1s1 s2s2 a b c
62
62 Example RE → NFA building NFA for a ( b|c )* s0s0 s1s1 a
63
63 Example RE → NFA NFA for a, b and c s4s4 s5s5 s6s6 s7s7 s0s0 s1s1 a b c
64
64 Example RE → NFA NFA for a and b|c s3s3 s4s4 s5s5 s6s6 s7s7 s8s8 s0s0 s1s1 a b c
65
65 Example RE → NFA NFA for a and ( b|c )* s3s3 s9s9 s4s4 s5s5 s6s6 s7s7 s8s8 s0s0 s1s1 s2s2 a b c
66
66 Example RE → NFA NFA for a ( b|c )* s3s3 s9s9 s4s4 s5s5 s6s6 s7s7 s8s8 s0s0 s1s1 s2s2 a b c
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.