Download presentation

Presentation is loading. Please wait.

Published byAmari Thorman Modified over 3 years ago

1
Finite Automata CPSC 388 Ellen Walker Hiram College

2
Machine Model of Computation Strings in the language are accepted Strings not in the language are rejected

3
Deterministic Finite Automaton Accepts strings with an odd number of 1’s (e.g. 1011, 110111, 10, 01110)

4
Parts of a DFA An alphabet ( ) A finite set of states (S) A deterministic set of transitions from one state to the next (T : S x S) One start state (s 0 S) One or more accepting states (A S)

5
Deterministic Transition Table

6
Testing some strings 1001reject 0101reject 10101accept 0reject 1accept 010101011accept

7
Results

8
Data for DFA in C++ Class State{ Public: string name; int index; // unique integer bool isFinal; //true if final state } State start; State next [MAXSTATES][MAXCHARS];

9
Implementing DFA in C++ //Construct all the states, set isFinal //Create next array from transitions int machine(istream &sin){ //sin.get() reads a single character from sin for(State S=start; c=sin.get(); S=next[S.index][c]); //Action for S would go here... return S.isFinal; }

10
What Language is This?

11
Draw DFA for: {aa, ab, bb} (ab)* (a+ab+aab)*b All strings with 1 a and 2 b’s All strings containing ab All strings that don’t contain ab All strings that don’t contain abc

12
Deterministic vs. Non-Deterministic Deterministic: exactly one new state for a given state,character pair Non-deterministic: 0 or more new states for each state,character pair –Assume machine will always make the right choice! –Add -transitions (move w/o symbol)

13
NFA: All strings containing “ab”

14
Are NFA’s More Powerful? Yes if... –There is at least one language that can be accepted by an NFA but no DFA No if … –For every NFA, we can make a DFA that accepts the same language

15
From NFA to DFA Each DFA state corresponds to a set of states in the NFA –DFA has max 2 n states if NFA has n states (still finite) Transition from {s1,s2} on a is union of transitions from s1 on a and s2 on a

16
Conversion Algorithm Copy the transitions from the start state. Choose one of the “new state” sets. Create a new row for that set, and construct its transitions (by unioning transitions from original table) Repeat until every set in the table has a row

17
Example: DFA for (a|b)*ab(a|b)* Initial NFA table Copy start state, create transition for {s1,s2}

18
Final NFA

19
Minimizing DFA If 2 states have different isFinal, they are different If 2 states have transitions on the same character to states that are known different, they are different Otherwise, the states are the same and can be merged (repeat until all different)

20
Minimization Example s1 != {s1,s3} s1 != {s1,s2,s3} (final) s1 != {s1,s2} (transition on b) {s1,s2} != {s1,s3} {s1,s2} != {s1,s2,s3} (final) We cannot say {s1,s3} != {s1,s2,s3}, so merge!

21
Why minimize? Implement machine with smaller table Compare two machines –If both are minimized, if both compute the same language, then the machines will be identical except for state names

22
DFA and Regular Expression The set of languages accepted by DFA’s = the set of languages accepted by regular expressions –For every r.e. we can make a DFA that accepts the same language –For every DFA we can make a r.e. that accepts the same language

23
For every r.e. there is a DFA... If we can construct an NFA, that’s good enough Prove by induction: –Base cases: , , a (element of ) -- build an NFA for each. –Step cases: r | s, rs, r* -- build resulting NFA from NFA’s from r and/or s

Similar presentations

OK

Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.

Lexical Analysis III Recognizing Tokens Lecture 4 CS 4318/5331 Apan Qasem Texas State University Spring 2015.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on cross docking disadvantages Ppt on semiconductor diodes Ppt on conservation of nature Ppt on childhood obesity in india Ppt on self awareness quotes Ppt on google company profile Ppt on network switching operator Ppt on child labour free download in hindi Ppt on thermal power plant operation Ppt on inhabiting other planets with water