Course Material CS 301 - Lecture 1 Deterministic Finite...

19
•1 CS 301 - Lecture 1 Deterministic Finite Automata Fall 2008 Course Material • Website:http://www.cs.colostate.edu/~cs301 – Syllabus, Outline, Grading Policies – Homework and Slides Instructor: Dan Massey – Office hours: 2-3pm Tues and Wed – Email: [email protected] Teaching Assistant: William Springer – Email: [email protected] Grading and Policies • Grading – 10% Homework – 30% Quizes – 30% Midterm – 30% Final Grading Policy – No credit for late homework. No exceptions. – No credit for missed exams. No make-up exams. Workload Weekly Reading Assignments Course will cover most of both books Weekly Homework Assignments Available from course website by Friday morning Due in lecture the following Thursday • Exams Midterm + final (comprehensive) In class, closed book, one double-sided cheat sheet allowed

Transcript of Course Material CS 301 - Lecture 1 Deterministic Finite...

Page 1: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 1

CS 301 - Lecture 1 Deterministic Finite Automata

Fall 2008

Course Material

•  Website:http://www.cs.colostate.edu/~cs301 – Syllabus, Outline, Grading Policies – Homework and Slides

•  Instructor: Dan Massey – Office hours: 2-3pm Tues and Wed – Email: [email protected]

•  Teaching Assistant: William Springer – Email: [email protected]

Grading and Policies •  Grading

– 10% Homework – 30% Quizes – 30% Midterm – 30% Final

•  Grading Policy – No credit for late homework. No exceptions. – No credit for missed exams. No make-up exams.

Workload •  Weekly Reading Assignments

–  Course will cover most of both books

•  Weekly Homework Assignments –  Available from course website by Friday morning –  Due in lecture the following Thursday

•  Exams –  Midterm + final (comprehensive) –  In class, closed book, one double-sided cheat sheet

allowed

Page 2: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 2

Administrative

•  You are responsible for knowing course, department, and university policies – READ THE SYLLABUS – PROVIDES LINKS TO DEPT POLICIES

•  Plagiarism – see definition – http://writing.colostate.edu/guides/teaching/

plagiarism/

•  Conflict Resolution web site – http://www.conflictresolution.colostate.edu/

About These Slides

•  Slides Originally Developed by Prof. Costas Busch (2004) – Many thanks to Prof. Busch for developing the

original slide set.

•  Adapted with permission by Prof. Dan Massey (Spring 2007) – Subsequent modifications

•  A language is a set of strings

•  String: A sequence of letters

–  Examples: “cat”, “dog”, “house”, …

–  Defined over an alphabet:

{ }zcba ,,,, …=Σ

Languages Alphabets and Strings •  We will use small alphabets: •  Strings

abbawbbbaaavabu

=

=

=

{ }ba,=Σ

baaabbbaabababaabbaaba

Page 3: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 3

m

nbbbvaaaw

21

21=

=

bbbaaaabba

mn bbbaaawv 2121=

Concatenation => abbabbbaaa

String Concatenation

12aaaw nR

=naaaw 21=

ababaaabbb Reverse => bbbaaababa

String Reverse

String Length

naaaw 21=nw =

124

=

=

=

aaaabba

Length =

Length and Concatenation vuuv +=

8538

5,3,

=+=+=

==

==

==

vuuvaababaabuv

vabaabvuaabu

Does this prove the formula is true? Can you prove the formula is true?

Page 4: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 4

Empty String

•  A string with no letters:

•  Observations:

λ

abbaabbaabba

www

==

==

=

λλ

λλ

λ 0

Substring •  Subsequence of consecutive characters

•  String Substring

bbabbabbaab

abbababbababbababbab

Prefix and Suffix

abbab

abbababbaabbabaλ

λ

babbabbbababbab

uvw =prefix suffix

More Concatenation

n

n wwww =

( ) abbaabbaabba =2

λ=0w

( ) λ=0abba

Page 5: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 5

*ΣΣ

{ }{ }…,,,,,,,,,*,

aabaaabbbaabaababaλ=Σ

The * Operation

Given an alphabet

Is the set of all strings over the alphabet

Σ

The + Operation

Given an alphabet

Is the set of all strings over the alphabet minus +Σ λλ−Σ=Σ+ *

{ }…,,,,,,,, aabaaabbbaabaaba=Σ+

{ }{ }…,,,,,,,,,*,

aabaaabbbaabaababaλ=Σ

Languages *Σ

{ }{ }…,,,,,,,,*,

aaabbbaabaababaλ=Σ

{ }{ }

},,,,,{,,

aaaaaaabaababaabbaaabaaa

λ

λ

A Language is any subset of

Given an alphabet:

Some Languages over this alphabet include:

}{}{ λ≠=∅

0}{ =∅=

1}{ =λ

0=λ

Sets

Set size

Set size

String length

Languages, Sets, and Notations

Page 6: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 6

An Infinite Language

}0:{ ≥= nbaL nn

aaaaabbbbbaabbabλ

L∈ Labb∉

What is the alphabet associated with this language?

Languages and Operations

{ } { }{ } { }{ } { } { }aaaaaabbbaaaaaba

ababbbaaaaabaaaaabbabaabbbaaaaaba

,,,,}{,,,

},,,{,,,

=−

=

=

A language is a set and set operations apply

The Complement of a Language

LL −Σ= *

{ } { }…,,,,,,, aaabbabaabbaa λ=

Intuitively, all strings not in the language. More precisely:

Is ccc in the complement of this language?

Reverse }:{ LwwL RR ∈=

{ } { }ababbaabababaaabab R ,,,, =

}0:{

}0:{

≥=

≥=

nabL

nbaL

nnR

nn

Page 7: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 7

Concatenation

{ }2121 ,: LyLxxyLL ∈∈=

{ }{ }

{ }baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

=

More Concatenation

n

n LLLL =

{ } { }{ }{ }{ }bbbbbababbaaabbabaaabaaa

babababa,,,,,,,

,,,, 3 ==

{ }

{ } { }λ

λ

=

=

0

0

,, aaabbaa

L

Star-Closure (Kleene *)

210* LLLL =

{ }

=

…,,,,,,,,

,,,

*,

abbbbabbaaabbaaabbbbbbaabbaa

bbabba

λ

Is Our Notation Sufficient?

}0:{ ≥= nbaL nn

}0,:{2 ≥= mnbabaL mmnn2Laabbaaabbb∈

Describe a language by listing all the strings in the language

But this only works for finite languages

Describe a language by listing some pattern such as:

But this has limits as well…. Consider the language of all valid English sentences

Page 8: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 8

Automata Finite Automaton Input

String Output

String

Finite Automaton

Finite Accepter Input

“Accept” or “Reject”

String

Finite Automaton

Output

Transition Graph

initial state

final state “accept” state

transition

Abba -Finite Accepter

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 9: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 9

Initial Configuration

1q 2q 3q 4qa b b a

5q

a a bb

ba,

Input String a b b a

ba,

0q

Reading the Input

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

Page 10: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 10

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b b a

ba,

0q 1q 2q 3q 4qa b b a

Output: “accept”

5q

a a bb

ba,

a b b a

ba,

Input finished

String Rejection

1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

0q 0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

Page 11: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 11

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,Output: “reject”

a b a

ba,

Input finished The Empty String

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

λ

Page 12: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 12

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Output: “reject”

λ

Would it be possible to accept the empty string?

Another Example

a

b ba,

ba,

0q 1q 2q

a ba

a

b ba,

ba,

0q 1q 2q

a ba

a

b ba,

ba,

0q 1q 2q

a ba

Page 13: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 13

a

b ba,

ba,

0q 1q 2q

a ba

a

b ba,

ba,

0q 1q 2q

a ba

Output: “accept”

Input finished

Rejection

a

b ba,

ba,

0q 1q 2q

ab b

a

b ba,

ba,

0q 1q 2q

ab b

Page 14: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 14

a

b ba,

ba,

0q 1q 2q

ab b

a

b ba,

ba,

0q 1q 2q

ab b

a

b ba,

ba,

0q 1q 2q

ab b

Output: “reject”

Input finished

Which strings are accepted?

Formalities

•  Deterministic Finite Accepter (DFA)

( )FqQM ,,,, 0δΣ=

δ

0q

F

: set of states

: input alphabet

: transition function

: initial state

: set of final states

Page 15: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 15

Input Alphabet Σ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

{ }ba,=Σ

ba,

Set of States Q

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

{ }543210 ,,,,, qqqqqqQ =

ba,

Initial State 0q

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Set of Final States F

0q 1q 2q 3qa b b a

5q

a a bb

ba,

{ }4qF =

ba,

4q

Page 16: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 16

Transition Function δ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

QQ →Σ×:δ

ba,

( ) 10, qaq =δ

2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q

( ) 50, qbq =δ

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q 0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

( ) 32, qbq =δ

Page 17: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 17

Transition Function δ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

δ a b0q

1q

2q

3q

4q

5q

1q 5q

5q 2q5q 3q

4q 5q

ba,5q5q5q5q

Extended Transition Function *δ

QQ →Σ× *:*δ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

( ) 20,* qabq =δ

3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q 2q

( ) 40,* qabbaq =δ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 18: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 18

( ) 50,* qabbbaaq =δ

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

( ) qwq ′=,*δ

Observation: There is a walk from to with label

q q′w

q q′w

q q′kw σσσ 21=

1σ 2σ kσ

( ) 50,* qabbbaaq =δ

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Example: There is a walk from to with label

0qabbbaa

5q Recursive Definition ( )( ) )),,(*(,*,*

σδδσδ

λδ

wqwqqq=

=

q q′σw1q

( )

qq

qwq

′=

′=

),(

,*

1 σδ

σδ

( )

( ) 1

1

,*

),(,*

qwq

qwq

=

=

δ

σδσδ

( ) )),,(*(,* σδδσδ wqwq =

Page 19: Course Material CS 301 - Lecture 1 Deterministic Finite ...massey/Teaching/cs301/RestrictedAccess/S… · •3 m n vbbb waaa 12 12 = = bbbaaa abba wv=a 1a 2 a nb 1b 2 b m Concatenation

• 19

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

( )( )

( )( )( )( )( )

( )

2

1

0

0

0

0

,,,

,,,*),,(*

,*

qbq

baqbaq

baqabq

=

=

=

=

=

δ

δδ

λδδδ

δδ

δ

Languages Accepted by DFAs •  Take DFA

•  Definition: – The language contains all input

strings accepted by

–  = { strings that drive to a final state}

M

( )MLM

( )ML M

What’s Next •  Read

–  Linz Chapter 1, Chapter 2.1 - 2.3 –  JFLAP Startup, Chapter 1, 2.1

•  Next Lecture Topics from Chapter 2.1 and 2.2 –  Regular Languages –  NonDeterministic Finite Automata

•  Homework 1 –  Due Thursday