You are on page 1of 76

Critical CS Questions

What is a computer? And What is a Computation?

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.1

Critical CS Questions
What is a computer? And What is a Computation? real computers too complex for any theory

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.1

Critical CS Questions
What is a computer? And What is a Computation? real computers too complex for any theory need manageable mathematical abstraction

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.1

Critical CS Questions
What is a computer? And What is a Computation? real computers too complex for any theory need manageable mathematical abstraction idealized models: accurate in some ways, but not in all details

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.1

Finite Automata
formal denition of nite automata

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Finite Automata
formal denition of nite automata deterministic vs. non-deterministic nite automata

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Finite Automata
formal denition of nite automata deterministic vs. non-deterministic nite automata regular languages

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Finite Automata
formal denition of nite automata deterministic vs. non-deterministic nite automata regular languages operations on regular languages

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Finite Automata
formal denition of nite automata deterministic vs. non-deterministic nite automata regular languages operations on regular languages regular expressions

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Finite Automata
formal denition of nite automata deterministic vs. non-deterministic nite automata regular languages operations on regular languages regular expressions pumping lemma

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.2

Example: A One-Way Automatic Door

front pad

rear pad

door

open when person approaches

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.3

Example: A One-Way Automatic Door

front pad

rear pad

door

open when person approaches hold open until person clears

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.3

Example: A One-Way Automatic Door

front pad

rear pad

door

open when person approaches hold open until person clears dont open when someone standing behind door
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.3

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States:

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.4

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.4

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN CLOSED

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.4

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN CLOSED Sensor:

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.4

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN CLOSED Sensor: FRONT: someone on front pad

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.4

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN CLOSED Sensor: FRONT: someone on front pad REAR: someone on rear pad
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.4

NEITHER

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

States: OPEN CLOSED Sensor: FRONT: someone on front pad REAR: someone on rear pad BOTH: someone(s) on both pads
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.4

NEITHER

The Automatic Door as DFA


REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

States: OPEN CLOSED Sensor: FRONT: someone on front pad REAR: someone on rear pad BOTH: someone(s) on both pads NEITHER no one on either pad.

NEITHER

p.4

The Automatic Door as DFA


DFA is Deterministic Finite Automata

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.5

The Automatic Door as DFA


DFA is Deterministic Finite Automata
REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

NEITHER

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.5

The Automatic Door as DFA


DFA is Deterministic Finite Automata
REAR BOTH NEITHER closed FRONT FRONT REAR BOTH open

NEITHER

neither front rear both closed closed open closed closed open closed open open open
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.5

DFA: Informal Denition


0 q1 1 q 2 0,1 1 0 q3

The machine M1 : states: q1 , q2 , and q3 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.6

DFA: Informal Denition


0 q1 1 q 2 0,1 1 0 q3

The machine M1 : states: q1 , q2 , and q3 . start state: q1 (arrow from outside).

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.6

DFA: Informal Denition


0 q1 1 q 2 0,1 1 0 q3

The machine M1 : states: q1 , q2 , and q3 . start state: q1 (arrow from outside). accept state: q2 (double circle).

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.6

DFA: Informal Denition


0 q1 1 q 2 0,1 1 0 q3

The machine M1 : states: q1 , q2 , and q3 . start state: q1 (arrow from outside). accept state: q2 (double circle). state transitions: arrows.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.6

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.7

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string DFA begins in start state q1

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.7

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string DFA begins in start state q1 after reading each symbol, DFA makes state transition with matching label.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.7

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string DFA begins in start state q1 after reading each symbol, DFA makes state transition with matching label. After reading last symbol, DFA produces output:

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.7

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string DFA begins in start state q1 after reading each symbol, DFA makes state transition with matching label. After reading last symbol, DFA produces output: accept if DFA is an accepting state.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.7

DFA: Informal Denition (cont.)


0 q1 1 q 2 0,1 1 0 q3

On an input string DFA begins in start state q1 after reading each symbol, DFA makes state transition with matching label. After reading last symbol, DFA produces output: accept if DFA is an accepting state. reject otherwise.
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.7

Informal Denition - Example


0 q1 1 q 2 0,1 1 0 q3

What happens on input strings 1101

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.8

Informal Denition - Example


0 q1 1 q 2 0,1 1 0 q3

What happens on input strings 1101 0010

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.8

Informal Denition - Example


0 q1 1 q 2 0,1 1 0 q3

What happens on input strings 1101 0010 01100

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.8

Informal Denition
0 q1 1 q 2 0,1 1 0 q3

This DFA accepts all input strings that end with a 1 all input strings that contain at least one 1, and end with an even number of 0s no other strings

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.9

Languages and Alphabets


An alphabet is a nite set of letters. = {a, b, c, . . . , z } the English alphabet. = {, , , . . . , } the Greek alphabet. = {0, 1} the binary alphabet. = {0, 1, . . . , 9} the digital alphabet.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.10

Languages and Alphabets


An alphabet is a nite set of letters. = {a, b, c, . . . , z } the English alphabet. = {, , , . . . , } the Greek alphabet. = {0, 1} the binary alphabet. = {0, 1, . . . , 9} the digital alphabet. The collection of all strings over is denoted by .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.10

Languages and Alphabets


An alphabet is a nite set of letters. = {a, b, c, . . . , z } the English alphabet. = {, , , . . . , } the Greek alphabet. = {0, 1} the binary alphabet. = {0, 1, . . . , 9} the digital alphabet. The collection of all strings over is denoted by . For the binary alphabet, , 1, 0, 000000000, 1111111000 are all members of .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.10

Languages and Examples


A language over is a subset L . For example Modern English.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and Examples


A language over is a subset L . For example Modern English. Ancient Greek.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and Examples


A language over is a subset L . For example Modern English. Ancient Greek. All prime numbers, writen using digits.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and Examples


A language over is a subset L . For example Modern English. Ancient Greek. All prime numbers, writen using digits. A = {w|w has at most seventeen 0s}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and Examples


A language over is a subset L . For example Modern English. Ancient Greek. All prime numbers, writen using digits. A = {w|w has at most seventeen 0s} B = {0n 1n |n 0}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and Examples


A language over is a subset L . For example Modern English. Ancient Greek. All prime numbers, writen using digits. A = {w|w has at most seventeen 0s} B = {0n 1n |n 0} C = {w |w has an equal number of 0s and 1s}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.11

Languages and DFA


Denition: L(M ), the language of a DFA M , is the set of strings L that M accepts, L(M ) = L.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.12

Languages and DFA


Denition: L(M ), the language of a DFA M , is the set of strings L that M accepts, L(M ) = L. Note that M may accept many strings, but M accepts only one language.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.12

Languages and DFA


Denition: L(M ), the language of a DFA M , is the set of strings L that M accepts, L(M ) = L. Note that M may accept many strings, but M accepts only one language. What language does M accept if it accepts no strings?

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.12

Languages and DFA


Denition: L(M ), the language of a DFA M , is the set of strings L that M accepts, L(M ) = L. Note that M may accept many strings, but M accepts only one language. What language does M accept if it accepts no strings? A language is called regular if some deterministic nite automaton accepts it.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.12

Formal Denitions
A deterministic nite automaton (DFA) is a 5-tuple (Q, , , q0 , F ), where Q is a nite set called the states, is a nite set called the alphabet, : Q Q is the transition function, q0 Q is the start state, and F Q is the set of accept states.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.13

Back to M1
0 q1 1 q 2 0,1 1 0 q3

M1 = (Q, , , q1 , F ) where Q = {q1 , q2 , q3 }, = {0, 1},

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.14

Back to M1
0 q1 1 q 2 0,1 1 0 q3

M1 = (Q, , , q1 , F ) where Q = {q1 , q2 , q3 }, = {0, 1}, the transition function is q1 q2 q3 0 1 q1 q2 q3 q2 q2 q2


p.14

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

Back to M1
0 q1 1 q 2 0,1 1 0 q3

M1 = (Q, , , q1 , F ) where Q = {q1 , q2 , q3 }, = {0, 1}, the transition function is q1 q2 q3 0 1 q1 q2 q3 q2 q2 q2


p.14

q1 is the start state, and F = {q2 }.


Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

Another Example

s a q1 b r1

q 2

r2

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.15

And Yet Another Example

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.16

A Formal Model of Computation


Let M = (Q, , , q0 , F ) be a DFA, and let w = w1 w2 wn be a string over . We say that M accepts w if there is a sequence of states r0 , . . . , rn (ri Q) such that r0 = q0

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.17

A Formal Model of Computation


Let M = (Q, , , q0 , F ) be a DFA, and let w = w1 w2 wn be a string over . We say that M accepts w if there is a sequence of states r0 , . . . , rn (ri Q) such that r0 = q0 (ri , wi+1 ) = ri+1 , 0 i < n

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.17

A Formal Model of Computation


Let M = (Q, , , q0 , F ) be a DFA, and let w = w1 w2 wn be a string over . We say that M accepts w if there is a sequence of states r0 , . . . , rn (ri Q) such that r0 = q0 (ri , wi+1 ) = ri+1 , 0 i < n rn F

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.17

The Regular Operations


Let A and B be languages. The union operation: AB = {x|x A or x B } The concatenation operation: AB = {xy |x A and y B } The star operation: A = {x1 x2 . . . xk |k 0 and each xi A}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.18

The Regular Operations Examples


Let A= {good, bad} and B = {boy, girl}. Union A B = {good, bad, boy, girl}

Concatenation A B = {goodboy, goodgirl, badboy, badgirl} Star


A = {, good, bad, goodgood, goodbad, badbad, badgood, . . .}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.19

Claim: Closure Under Union


If A1 and A2 are regular languages, so is A1 A2 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.20

Claim: Closure Under Union


If A1 and A2 are regular languages, so is A1 A2 . Approach to Proof: some M1 accepts A1 some M2 accepts A2 construct M that accepts A1 A2 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.20

Claim: Closure Under Union


If A1 and A2 are regular languages, so is A1 A2 . Approach to Proof: some M1 accepts A1 some M2 accepts A2 construct M that accepts A1 A2 . Attempted Proof Idea: rst simulate M1 , and if M1 doesnt accept, then simulate M2 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.20

Claim: Closure Under Union


If A1 and A2 are regular languages, so is A1 A2 . Approach to Proof: some M1 accepts A1 some M2 accepts A2 construct M that accepts A1 A2 . Attempted Proof Idea: rst simulate M1 , and if M1 doesnt accept, then simulate M2 . Whats wrong with this?
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.20

Claim: Closure Under Union


If A1 and A2 are regular languages, so is A1 A2 . Approach to Proof: some M1 accepts A1 some M2 accepts A2 construct M that accepts A1 A2 . Attempted Proof Idea: rst simulate M1 , and if M1 doesnt accept, then simulate M2 . Whats wrong with this? Fix: Simulate both machines simultaneously.
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.20

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.21

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 . Dene M as follows (M will accept L1 L2 ): Q = Q1 Q2 . is the same.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.21

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 . Dene M as follows (M will accept L1 L2 ): Q = Q1 Q2 . is the same. For each (r1 , r2 ) Q and a , ((r1 , r2 ), a) = (1 (r1 , a), 2 (r2 , a))

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.21

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 . Dene M as follows (M will accept L1 L2 ): Q = Q1 Q2 . is the same. For each (r1 , r2 ) Q and a , ((r1 , r2 ), a) = (1 (r1 , a), 2 (r2 , a)) q0 = (q1 , q2 )

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.21

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 . Dene M as follows (M will accept L1 L2 ): Q = Q1 Q2 . is the same. For each (r1 , r2 ) Q and a , ((r1 , r2 ), a) = (1 (r1 , a), 2 (r2 , a)) q0 = (q1 , q2 ) F = {(r1 , r2 )|r1 F1 or r2 F2 }.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.21

Closure Under Union: Correct Proof


Suppose M1 = (Q1 , , 1 , q1 , F1 ) accepts L1 , and M2 = (Q2 , , 2 , q2 , F2 ) accepts L2 . Dene M as follows (M will accept L1 L2 ): Q = Q1 Q2 . is the same. For each (r1 , r2 ) Q and a , ((r1 , r2 ), a) = (1 (r1 , a), 2 (r2 , a)) q0 = (q1 , q2 ) F = {(r1 , r2 )|r1 F1 or r2 F2 }. (hey, why not choose F = F1 F2 ?)
Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p.21

What About Concatenation?


Thm: If L1 , L2 are regular languages, so is L1 L2 . Example: L1 = {good, bad} and L2 = {boy, girl}. L1 L2 = {goodboy, goodgirl, badboy, badgirl}

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.22

What About Concatenation?


Thm: If L1 , L2 are regular languages, so is L1 L2 . Example: L1 = {good, bad} and L2 = {boy, girl}. L1 L2 = {goodboy, goodgirl, badboy, badgirl} This is much harder to prove. Idea: Simulate M1 for a while, then switch to M2 .

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.22

What About Concatenation?


Thm: If L1 , L2 are regular languages, so is L1 L2 . Example: L1 = {good, bad} and L2 = {boy, girl}. L1 L2 = {goodboy, goodgirl, badboy, badgirl} This is much harder to prove. Idea: Simulate M1 for a while, then switch to M2 . Problem: But when do you switch? This leads us into non-determinism.

Slides modied by Benny Chor, based on original slides by Maurice Herlihy, Brown University.

p.22

You might also like