COSC 3340 Introduction to Theory of Computation University

  • Slides: 22
Download presentation
COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 2

COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 2 1 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

1 st model -- Deterministic Finite Automaton (DFA) Read only Head Finite Control 2

1 st model -- Deterministic Finite Automaton (DFA) Read only Head Finite Control 2 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

DFA (contd. ) l The DFA has: – – – 3 a finite set

DFA (contd. ) l The DFA has: – – – 3 a finite set of states 1 special state - initial state 0 or more special states - final states input alphabet transition table containing (state, symbol) -> next state Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Informally -- How does a DFA work? l l An input string is placed

Informally -- How does a DFA work? l l An input string is placed on the tape (left-justified). DFA begins in the start state. Head placed on leftmost cell. DFA goes into a loop until the entire string is read. – In each step, DFA consults a transition table and changes state based on (s, ) where l l 4 s - current state - symbol scanned by head Lecture 2 Uof. H - COSC 3340 - Dr. Verma

How does a DFA work? (contd. ) l l 5 After reading input string,

How does a DFA work? (contd. ) l l 5 After reading input string, – if DFA state final, input accepted – if DFA state not final, input rejected Language of DFA -- set of all strings accepted by DFA. Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Pictorial representation of DFA (q, σ) -> q' 6 Lecture 2 Uof. H -

Pictorial representation of DFA (q, σ) -> q' 6 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Example: Diagram of DFA L = {a 2 n + 1 | n >=

Example: Diagram of DFA L = {a 2 n + 1 | n >= 0} l Answer: L = {a, aaaaa, . . . } 7 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 8 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 8 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 9 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 9 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 10 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 10 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 11 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aaa 11 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Formal definition of DFA l l DFA M = (Q, , , s, F)

Formal definition of DFA l l DFA M = (Q, , , s, F) Where, – Q is finite set of states is input alphabet s Q is initial state F Q is set of final states – : Q X -> Q – – – 12 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Formal definition of L(M) l l L(M) - Language accepted by M Define *:

Formal definition of L(M) l l L(M) - Language accepted by M Define *: – – l 13 *(q, ) = q *(q, wσ) = ( *(q, w), σ) Definition: L(M) = { w in * | * (s, w) in F }. Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Example: L(M) = {w in {a, b}* | w contains even no. of a's}

Example: L(M) = {w in {a, b}* | w contains even no. of a's} 14 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 15 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 15 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 16 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 16 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 17 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step aa 17 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 18 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 18 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 19 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 19 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 20 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

JFLAP Step-By-Step ab 20 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Given a language, how to define DFA? l Creative process requiring you to: (i)

Given a language, how to define DFA? l Creative process requiring you to: (i) Put yourself in DFA's shoes (ii) Find finite amount of info, based on which string accepted/rejected (iii) From step (ii), determine number of states and then transitions. 21 Lecture 2 Uof. H - COSC 3340 - Dr. Verma

Regular Languages l l Definition: A Language is regular iff there is a DFA

Regular Languages l l Definition: A Language is regular iff there is a DFA that accepts it. Examples: – – – 22 { } * {w in {0, 1}* | second symbol of w is a 1} Exercise {w in {0, 1}* | second last symbol of w is a 1} Exercise {w in {0, 1}* | w contains 010 as a substring} - (importance? ) Lecture 2 Uof. H - COSC 3340 - Dr. Verma