Top Banner
CSE 135: Introduction to Theory of Computation Sungjin Im University of California, Merced Spring 2014
165

CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Jun 30, 2018

Download

Documents

lamngoc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

CSE 135: Introduction to Theory of Computation

Sungjin Im

University of California, Merced

Spring 2014

Page 2: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Decision Problems

Decision ProblemsGiven input, decide “yes” or “no”

I Examples: Is x an evennumber? Is x prime? Isthere a path from s to t ingraph G?

I i.e., Compute a booleanfunction of input

General ComputationalProblemIn contrast, typically a problemrequires computing somenon-boolean function, or carryingout interactive/reactivecomputation in a distributedenvironment

I Examples: Find the factorsof x . Find the balance inaccount number x .

I In this course, we will study decision problems because aspectsof computability are captured by this special class of problems

Page 3: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Decision Problems

Decision ProblemsGiven input, decide “yes” or “no”

I Examples: Is x an evennumber? Is x prime? Isthere a path from s to t ingraph G?

I i.e., Compute a booleanfunction of input

General ComputationalProblemIn contrast, typically a problemrequires computing somenon-boolean function, or carryingout interactive/reactivecomputation in a distributedenvironment

I Examples: Find the factorsof x . Find the balance inaccount number x .

I In this course, we will study decision problems because aspectsof computability are captured by this special class of problems

Page 4: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Decision Problems

Decision ProblemsGiven input, decide “yes” or “no”

I Examples: Is x an evennumber? Is x prime? Isthere a path from s to t ingraph G?

I i.e., Compute a booleanfunction of input

General ComputationalProblemIn contrast, typically a problemrequires computing somenon-boolean function, or carryingout interactive/reactivecomputation in a distributedenvironment

I Examples: Find the factorsof x . Find the balance inaccount number x .

I In this course, we will study decision problems because aspectsof computability are captured by this special class of problems

Page 5: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)

I Includes the values of variables (and the “program counter”)I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 6: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)

I Includes the values of variables (and the “program counter”)I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 7: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)

I Includes the values of variables (and the “program counter”)I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 8: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)I Includes the values of variables (and the “program counter”)

I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 9: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)I Includes the values of variables (and the “program counter”)I State evolves throughout the computation

I Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 10: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)I Includes the values of variables (and the “program counter”)I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 11: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

What Does a Computation Look Like?

I Some code (a.k.a. control): the same for all instances

I The input (a.k.a. problem instance): encoded as a string overa finite alphabet

I As the program starts executing, some memory (a.k.a. state)I Includes the values of variables (and the “program counter”)I State evolves throughout the computationI Often, takes more memory for larger problem instances

I But some programs do not need larger state for largerinstances!

Page 12: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite State Computation

I Finite state: A fixed upper bound on the size of the state,independent of the size of the input

I A sequential program with no dynamic allocation usingvariables that take boolean values (or values in a finiteenumerated data type)

I If t-bit state, at most 2t possible states

I Not enough memory to hold the entire input

I “Streaming input”: automaton runs (i.e., changes state) onseeing each bit of input

Page 13: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite State Computation

I Finite state: A fixed upper bound on the size of the state,independent of the size of the input

I A sequential program with no dynamic allocation usingvariables that take boolean values (or values in a finiteenumerated data type)

I If t-bit state, at most 2t possible states

I Not enough memory to hold the entire input

I “Streaming input”: automaton runs (i.e., changes state) onseeing each bit of input

Page 14: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite State Computation

I Finite state: A fixed upper bound on the size of the state,independent of the size of the input

I A sequential program with no dynamic allocation usingvariables that take boolean values (or values in a finiteenumerated data type)

I If t-bit state, at most 2t possible states

I Not enough memory to hold the entire input

I “Streaming input”: automaton runs (i.e., changes state) onseeing each bit of input

Page 15: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite State Computation

I Finite state: A fixed upper bound on the size of the state,independent of the size of the input

I A sequential program with no dynamic allocation usingvariables that take boolean values (or values in a finiteenumerated data type)

I If t-bit state, at most 2t possible states

I Not enough memory to hold the entire input

I “Streaming input”: automaton runs (i.e., changes state) onseeing each bit of input

Page 16: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite State Computation

I Finite state: A fixed upper bound on the size of the state,independent of the size of the input

I A sequential program with no dynamic allocation usingvariables that take boolean values (or values in a finiteenumerated data type)

I If t-bit state, at most 2t possible states

I Not enough memory to hold the entire inputI “Streaming input”: automaton runs (i.e., changes state) on

seeing each bit of input

Page 17: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

An Automatic Door

Frontpad

Rearpad

door

Top view of Door

closed open

front

neither

rearboth

neither

frontrearboth

State diagram of controller

I Input: A stream of events <front>, <rear>, <both>,<neither> . . .

I Controller has a single bit of state.

Page 18: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

An Automatic Door

Frontpad

Rearpad

door

Top view of Door

closed open

front

neither

rearboth

neither

frontrearboth

State diagram of controller

I Input: A stream of events <front>, <rear>, <both>,<neither> . . .

I Controller has a single bit of state.

Page 19: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

An Automatic Door

Frontpad

Rearpad

door

Top view of Door

closed open

front

neither

rearboth

neither

frontrearboth

State diagram of controller

I Input: A stream of events <front>, <rear>, <both>,<neither> . . .

I Controller has a single bit of state.

Page 20: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

An Automatic Door

Frontpad

Rearpad

door

Top view of Door

closed open

front

neither

rearboth

neither

frontrearboth

State diagram of controller

I Input: A stream of events <front>, <rear>, <both>,<neither> . . .

I Controller has a single bit of state.

Page 21: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite AutomataDetails

AutomatonA finite automaton has:

Finite set of states,with start/initial and accepting/final states;Transitions from one state to another onreading a symbol from the input.

Computation

Start at the initial state; in each step, read thenext symbol of the input, take the transition(edge) labeled by that symbol to a new state.

Acceptance/Rejection: If after reading theinput w , the machine is in a final state then wis accepted; otherwise w is rejected.

q0 q1

0 0

1

1

Transition Diagram of

automaton

Page 22: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite AutomataDetails

AutomatonA finite automaton has: Finite set of states,with start/initial and accepting/final states;

Transitions from one state to another onreading a symbol from the input.

Computation

Start at the initial state; in each step, read thenext symbol of the input, take the transition(edge) labeled by that symbol to a new state.

Acceptance/Rejection: If after reading theinput w , the machine is in a final state then wis accepted; otherwise w is rejected.

q0 q1

0 0

1

1

Transition Diagram of

automaton

Page 23: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite AutomataDetails

AutomatonA finite automaton has: Finite set of states,with start/initial and accepting/final states;Transitions from one state to another onreading a symbol from the input.

Computation

Start at the initial state; in each step, read thenext symbol of the input, take the transition(edge) labeled by that symbol to a new state.

Acceptance/Rejection: If after reading theinput w , the machine is in a final state then wis accepted; otherwise w is rejected.

q0 q1

0 0

1

1

Transition Diagram of

automaton

Page 24: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite AutomataDetails

AutomatonA finite automaton has: Finite set of states,with start/initial and accepting/final states;Transitions from one state to another onreading a symbol from the input.

Computation

Start at the initial state; in each step, read thenext symbol of the input, take the transition(edge) labeled by that symbol to a new state.

Acceptance/Rejection: If after reading theinput w , the machine is in a final state then wis accepted; otherwise w is rejected.

q0 q1

0 0

1

1

Transition Diagram of

automaton

Page 25: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite AutomataDetails

AutomatonA finite automaton has: Finite set of states,with start/initial and accepting/final states;Transitions from one state to another onreading a symbol from the input.

Computation

Start at the initial state; in each step, read thenext symbol of the input, take the transition(edge) labeled by that symbol to a new state.Acceptance/Rejection: If after reading theinput w , the machine is in a final state then wis accepted; otherwise w is rejected.

q0 q1

0 0

1

1

Transition Diagram of

automaton

Page 26: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example: Computation

I On input 1001, the computation is

1. Start in state q0. Read 1 and goto q1.2. Read 0 and goto q1.3. Read 0 and goto q1.4. Read 1 and goto q0. Since q0 is not a

final state 1001 is rejected.

I On input 010, the computation is

1. Start in state q0. Read 0 and goto q0.2. Read 1 and goto q1.3. Read 0 and goto q1. Since q1 is a final

state 010 is accepted.

q0 q1

0 0

1

1

Page 27: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example: Computation

I On input 1001, the computation is

1. Start in state q0. Read 1 and goto q1.2. Read 0 and goto q1.3. Read 0 and goto q1.4. Read 1 and goto q0. Since q0 is not a

final state 1001 is rejected.

I On input 010, the computation is

1. Start in state q0. Read 0 and goto q0.2. Read 1 and goto q1.3. Read 0 and goto q1. Since q1 is a final

state 010 is accepted.

q0 q1

0 0

1

1

Page 28: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example I

q0

0, 1

Automaton accepts all strings of 0s and 1s

Page 29: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example I

q0

0, 1

Automaton accepts all strings of 0s and 1s

Page 30: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example II

q0 q1

0 1

1

0

Automaton accepts strings ending in 1

Page 31: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example II

q0 q1

0 1

1

0

Automaton accepts strings ending in 1

Page 32: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example III

q0 q1

0 0

1

1

Automaton accepts strings having an odd number of 1s

Page 33: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example III

q0 q1

0 0

1

1

Automaton accepts strings having an odd number of 1s

Page 34: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example IV

q0 q1

q2q3

1

1

1

1

0 0 0 0

Automaton accepts strings having an odd number of 1s and odd number

of 0s

Page 35: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example IV

q0 q1

q2q3

1

1

1

1

0 0 0 0

Automaton accepts strings having an odd number of 1s and odd number

of 0s

Page 36: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Finite Automata in Practice

I grep

I Thermostats

I Coke Machines

I Elevators

I Train Track Switches

I Security Properties

I Lexical Analyzers for Parsers

Page 37: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Alphabet

DefinitionAn alphabet is any finite, non-empty set of symbols. We willusually denote it by Σ.

Example

Examples of alphabets include {0, 1} (binary alphabet);{a, b, . . . , z} (English alphabet); the set of all ASCII characters;{moveforward, moveback, rotate90}.

Page 38: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings

DefinitionA string or word over alphabet Σ is a (finite) sequence of symbolsin Σ. Examples are ‘0101001’, ‘string’, ‘〈moveback〉〈rotate90〉’

I ε is the empty string.

I The length of string u (denoted by |u|) is the number ofsymbols in u. Example, |ε| = 0, |011010| = 6.

I Concatenation: uv is the string that has a copy of u followedby a copy of v . Example, if u = ‘cat ′ and v = ‘nap′ thenuv = ‘catnap′. If v = ε the uv = vu = u.

I u is a prefix of v if there is a string w such that v = uw .Example ‘cat ′ is a prefix of ‘catnap′.

Page 39: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings

DefinitionA string or word over alphabet Σ is a (finite) sequence of symbolsin Σ. Examples are ‘0101001’, ‘string’, ‘〈moveback〉〈rotate90〉’I ε is the empty string.

I The length of string u (denoted by |u|) is the number ofsymbols in u. Example, |ε| = 0, |011010| = 6.

I Concatenation: uv is the string that has a copy of u followedby a copy of v . Example, if u = ‘cat ′ and v = ‘nap′ thenuv = ‘catnap′. If v = ε the uv = vu = u.

I u is a prefix of v if there is a string w such that v = uw .Example ‘cat ′ is a prefix of ‘catnap′.

Page 40: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings

DefinitionA string or word over alphabet Σ is a (finite) sequence of symbolsin Σ. Examples are ‘0101001’, ‘string’, ‘〈moveback〉〈rotate90〉’I ε is the empty string.

I The length of string u (denoted by |u|) is the number ofsymbols in u. Example, |ε| = 0, |011010| = 6.

I Concatenation: uv is the string that has a copy of u followedby a copy of v . Example, if u = ‘cat ′ and v = ‘nap′ thenuv = ‘catnap′. If v = ε the uv = vu = u.

I u is a prefix of v if there is a string w such that v = uw .Example ‘cat ′ is a prefix of ‘catnap′.

Page 41: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings

DefinitionA string or word over alphabet Σ is a (finite) sequence of symbolsin Σ. Examples are ‘0101001’, ‘string’, ‘〈moveback〉〈rotate90〉’I ε is the empty string.

I The length of string u (denoted by |u|) is the number ofsymbols in u. Example, |ε| = 0, |011010| = 6.

I Concatenation: uv is the string that has a copy of u followedby a copy of v . Example, if u = ‘cat ′ and v = ‘nap′ thenuv = ‘catnap′. If v = ε the uv = vu = u.

I u is a prefix of v if there is a string w such that v = uw .Example ‘cat ′ is a prefix of ‘catnap′.

Page 42: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings

DefinitionA string or word over alphabet Σ is a (finite) sequence of symbolsin Σ. Examples are ‘0101001’, ‘string’, ‘〈moveback〉〈rotate90〉’I ε is the empty string.

I The length of string u (denoted by |u|) is the number ofsymbols in u. Example, |ε| = 0, |011010| = 6.

I Concatenation: uv is the string that has a copy of u followedby a copy of v . Example, if u = ‘cat ′ and v = ‘nap′ thenuv = ‘catnap′. If v = ε the uv = vu = u.

I u is a prefix of v if there is a string w such that v = uw .Example ‘cat ′ is a prefix of ‘catnap′.

Page 43: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Languages

Definition

I For alphabet Σ, Σ∗ is the set of all strings over Σ. Σn is theset of all strings of length n.

I A language over Σ is a set L ⊆ Σ∗. For exampleL = {1, 01, 11, 001} is a language over {0, 1}.

I A language L defines a decision problem:

Inputs (strings)whose answer is ‘yes’ are exactly those belonging to L

Page 44: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Languages

Definition

I For alphabet Σ, Σ∗ is the set of all strings over Σ. Σn is theset of all strings of length n.

I A language over Σ is a set L ⊆ Σ∗. For exampleL = {1, 01, 11, 001} is a language over {0, 1}.

I A language L defines a decision problem:

Inputs (strings)whose answer is ‘yes’ are exactly those belonging to L

Page 45: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Languages

Definition

I For alphabet Σ, Σ∗ is the set of all strings over Σ. Σn is theset of all strings of length n.

I A language over Σ is a set L ⊆ Σ∗. For exampleL = {1, 01, 11, 001} is a language over {0, 1}.

I A language L defines a decision problem:

Inputs (strings)whose answer is ‘yes’ are exactly those belonging to L

Page 46: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Languages

Definition

I For alphabet Σ, Σ∗ is the set of all strings over Σ. Σn is theset of all strings of length n.

I A language over Σ is a set L ⊆ Σ∗. For exampleL = {1, 01, 11, 001} is a language over {0, 1}.

I A language L defines a decision problem:

Inputs (strings)whose answer is ‘yes’ are exactly those belonging to L

Page 47: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Languages

Definition

I For alphabet Σ, Σ∗ is the set of all strings over Σ. Σn is theset of all strings of length n.

I A language over Σ is a set L ⊆ Σ∗. For exampleL = {1, 01, 11, 001} is a language over {0, 1}.

I A language L defines a decision problem: Inputs (strings)whose answer is ‘yes’ are exactly those belonging to L

Page 48: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Set Notation

We will often define languages using the set builder notation.Thus, L = {w ∈ Σ∗ | p(w)} is the collection of all strings w over Σthat satisfy the property p.

Example

I L = {w ∈ {0, 1}∗ | |w | is even} is

the set of all even lengthstrings over {0, 1}.

I L = {w ∈ {0, 1}∗ | there is a u such that wu = 10001} is

theset of all prefixes of 10001.

Page 49: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Set Notation

We will often define languages using the set builder notation.Thus, L = {w ∈ Σ∗ | p(w)} is the collection of all strings w over Σthat satisfy the property p.

Example

I L = {w ∈ {0, 1}∗ | |w | is even} is

the set of all even lengthstrings over {0, 1}.

I L = {w ∈ {0, 1}∗ | there is a u such that wu = 10001} is

theset of all prefixes of 10001.

Page 50: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Set Notation

We will often define languages using the set builder notation.Thus, L = {w ∈ Σ∗ | p(w)} is the collection of all strings w over Σthat satisfy the property p.

Example

I L = {w ∈ {0, 1}∗ | |w | is even} is the set of all even lengthstrings over {0, 1}.

I L = {w ∈ {0, 1}∗ | there is a u such that wu = 10001} is

theset of all prefixes of 10001.

Page 51: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Set Notation

We will often define languages using the set builder notation.Thus, L = {w ∈ Σ∗ | p(w)} is the collection of all strings w over Σthat satisfy the property p.

Example

I L = {w ∈ {0, 1}∗ | |w | is even} is the set of all even lengthstrings over {0, 1}.

I L = {w ∈ {0, 1}∗ | there is a u such that wu = 10001} is

theset of all prefixes of 10001.

Page 52: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Set Notation

We will often define languages using the set builder notation.Thus, L = {w ∈ Σ∗ | p(w)} is the collection of all strings w over Σthat satisfy the property p.

Example

I L = {w ∈ {0, 1}∗ | |w | is even} is the set of all even lengthstrings over {0, 1}.

I L = {w ∈ {0, 1}∗ | there is a u such that wu = 10001} is theset of all prefixes of 10001.

Page 53: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Defining an Automaton

To describe an automaton, we to need to specify

I What the alphabet is,

I What the states are,

I What the initial state is,

I What states are accepting/final, and

I What the transition from each state and input symbol is.

Thus, the above 5 things are part of the formal definition.

Page 54: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Deterministic

Finite AutomataFormal Definition

DefinitionA

deterministic

finite automaton

(DFA)

is M = (Q,Σ, δ, q0,F ),where

I Q is the finite set of states

I Σ is the finite alphabet

I δ : Q × Σ→ Q “Next-state” transition function

I q0 ∈ Q initial state

I F ⊆ Q final/accepting states

Given a state and a symbol, the next state is “determined”.

Page 55: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Deterministic Finite AutomataFormal Definition

DefinitionA deterministic finite automaton (DFA) is M = (Q,Σ, δ, q0,F ),where

I Q is the finite set of states

I Σ is the finite alphabet

I δ : Q × Σ→ Q “Next-state” transition function

I q0 ∈ Q initial state

I F ⊆ Q final/accepting states

Given a state and a symbol, the next state is “determined”.

Page 56: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Computation

DefinitionFor a DFA M = (Q,Σ, δ, q0,F ), let us define a functionδ : Q × Σ∗ → Q such that δ(q,w) is M’s state after reading wfrom state q.

Formally,

δ(q,w) =

{

q

if w = ε

δ(δ(q, u), a)

if w = ua

DefinitionWe say a DFA M = (Q,Σ, δ, q0,F ) accepts string w ∈ Σ∗ iffδ(q0,w) ∈ F .

Page 57: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Computation

DefinitionFor a DFA M = (Q,Σ, δ, q0,F ), let us define a functionδ : Q × Σ∗ → Q such that δ(q,w) is M’s state after reading wfrom state q. Formally,

δ(q,w) =

{

q

if w = ε

δ(δ(q, u), a)

if w = ua

DefinitionWe say a DFA M = (Q,Σ, δ, q0,F ) accepts string w ∈ Σ∗ iffδ(q0,w) ∈ F .

Page 58: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Computation

DefinitionFor a DFA M = (Q,Σ, δ, q0,F ), let us define a functionδ : Q × Σ∗ → Q such that δ(q,w) is M’s state after reading wfrom state q. Formally,

δ(q,w) =

{q if w = ε

δ(δ(q, u), a)

if w = ua

DefinitionWe say a DFA M = (Q,Σ, δ, q0,F ) accepts string w ∈ Σ∗ iffδ(q0,w) ∈ F .

Page 59: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Computation

DefinitionFor a DFA M = (Q,Σ, δ, q0,F ), let us define a functionδ : Q × Σ∗ → Q such that δ(q,w) is M’s state after reading wfrom state q. Formally,

δ(q,w) =

{q if w = ε

δ(δ(q, u), a) if w = ua

DefinitionWe say a DFA M = (Q,Σ, δ, q0,F ) accepts string w ∈ Σ∗ iffδ(q0,w) ∈ F .

Page 60: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Computation

DefinitionFor a DFA M = (Q,Σ, δ, q0,F ), let us define a functionδ : Q × Σ∗ → Q such that δ(q,w) is M’s state after reading wfrom state q. Formally,

δ(q,w) =

{q if w = ε

δ(δ(q, u), a) if w = ua

DefinitionWe say a DFA M = (Q,Σ, δ, q0,F ) accepts string w ∈ Σ∗ iffδ(q0,w) ∈ F .

Page 61: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Acceptance/Recognition

and Regular Languages

DefinitionThe language accepted or recognized by a DFA M over alphabet Σis L(M) = {w ∈ Σ∗ |M accepts w}.

A language L is said to beaccepted/recognized by M if L = L(M).

DefinitionA language L is regular if there is some DFA M such thatL = L(M).

Page 62: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Acceptance/Recognition

and Regular Languages

DefinitionThe language accepted or recognized by a DFA M over alphabet Σis L(M) = {w ∈ Σ∗ |M accepts w}. A language L is said to beaccepted/recognized by M if L = L(M).

DefinitionA language L is regular if there is some DFA M such thatL = L(M).

Page 63: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Acceptance/Recognition and Regular Languages

DefinitionThe language accepted or recognized by a DFA M over alphabet Σis L(M) = {w ∈ Σ∗ |M accepts w}. A language L is said to beaccepted/recognized by M if L = L(M).

DefinitionA language L is regular if there is some DFA M such thatL = L(M).

Page 64: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Formal Example of DFA

Example

q0 q1

0 0

1

1

Transition Diagram of DFA

0 1

q0 q0 q1q1 q1 q0

Transition Table representation

Formally the automaton is M = ({q0, q1}, {0, 1}, δ, q0, {q1}) where

δ(q0, 0) = q0 δ(q0, 1) = q1δ(q1, 0) = q1 δ(q1, 1) = q0

Page 65: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Formal Example of DFA

Example

q0 q1

0 0

1

1

Transition Diagram of DFA

0 1

q0 q0 q1q1 q1 q0

Transition Table representation

Formally the automaton is M = ({q0, q1}, {0, 1}, δ, q0, {q1}) where

δ(q0, 0) = q0 δ(q0, 1) = q1δ(q1, 0) = q1 δ(q1, 1) = q0

Page 66: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Formal Example of DFA

Example

q0 q1

0 0

1

1

Transition Diagram of DFA

0 1

q0 q0 q1q1 q1 q0

Transition Table representation

Formally the automaton is M = ({q0, q1}, {0, 1}, δ, q0, {q1}) where

δ(q0, 0) = q0 δ(q0, 1) = q1δ(q1, 0) = q1 δ(q1, 1) = q0

Page 67: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

A Simple Observation about DFAs

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.By induction! Let’s see . . . �

Page 68: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

A Simple Observation about DFAs

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.By induction! Let’s see . . . �

Page 69: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Domino Principle

I Line up n dominoes numbered0, 1, . . . n − 1 such that if we knock onethe next one will fall

I If Fi denotes “ith domino falls”, we haveFi → Fi+1

I Thus, knocking the 0th domino will causeall the dominoes to fall becauseF0

→ F1 → F2 → · · · → Fn−1

Dominoes

Page 70: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Domino Principle

I Line up n dominoes numbered0, 1, . . . n − 1 such that if we knock onethe next one will fall

I If Fi denotes “ith domino falls”, we haveFi → Fi+1

I Thus, knocking the 0th domino will causeall the dominoes to fall becauseF0

→ F1 → F2 → · · · → Fn−1

Dominoes

Page 71: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Domino Principle

I Line up n dominoes numbered0, 1, . . . n − 1 such that if we knock onethe next one will fall

I If Fi denotes “ith domino falls”, we haveFi → Fi+1

I Thus, knocking the 0th domino will causeall the dominoes to fall becauseF0 → F1

→ F2 → · · · → Fn−1

Dominoes

Page 72: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Domino Principle

I Line up n dominoes numbered0, 1, . . . n − 1 such that if we knock onethe next one will fall

I If Fi denotes “ith domino falls”, we haveFi → Fi+1

I Thus, knocking the 0th domino will causeall the dominoes to fall becauseF0 → F1 → F2

→ · · · → Fn−1

Dominoes

Page 73: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Domino Principle

I Line up n dominoes numbered0, 1, . . . n − 1 such that if we knock onethe next one will fall

I If Fi denotes “ith domino falls”, we haveFi → Fi+1

I Thus, knocking the 0th domino will causeall the dominoes to fall becauseF0 → F1 → F2 → · · · → Fn−1

Dominoes

Page 74: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Plato’s Infinite Domino Principle

Principle

Imagine one domino for each natural number0, 1, 2, . . ., arranged in an infinite row.Knocking the 0th domino will knock them all.

Plato

“Proof”Suppose they don’t all fall. Let k > 0 be the smallest numbereddomino that remains standing. This means domino k − 1 fell. Butthen k − 1 will knock k over. Therefore, k must fall and remainstanding, which is a contradiction.

Page 75: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Plato’s Infinite Domino Principle

Principle

Imagine one domino for each natural number0, 1, 2, . . ., arranged in an infinite row.Knocking the 0th domino will knock them all.

Plato

“Proof”Suppose they don’t all fall. Let k > 0 be the smallest numbereddomino that remains standing. This means domino k − 1 fell. Butthen k − 1 will knock k over. Therefore, k must fall and remainstanding, which is a contradiction.

Page 76: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Plato’s Infinite Domino PrincipleFormally

Mathematically we can say

I Fi : ith domino falls

I Suppose for every natural number i , Fi → Fi+1

I Suppose 0th domino is knocked over, i.e., F0I Then all dominoes will fall, i.e., ∀i .Fi .

Page 77: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Dominoes and Mathematical Induction

Domino Principle

I Infinite sequence ofdominoes

I Knock the 0th domino

I Arrange dominoes suchthat knocking one willknock the next one

I Conclude all dominoesfall

Induction Principle

I Infinite sequence of statementsS0, S1, . . .

I Prove S0 is correct [Base Case]

I For an arbitrary i , assuming S1to be correct

[InductionHypothesis]

establishes Si+1 tobe correct

[Induction Step]

I Conclude ∀i . Si is true

Page 78: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Dominoes and Mathematical Induction

Domino Principle

I Infinite sequence ofdominoes

I Knock the 0th domino

I Arrange dominoes suchthat knocking one willknock the next one

I Conclude all dominoesfall

Induction Principle

I Infinite sequence of statementsS0, S1, . . .

I Prove S0 is correct [Base Case]

I For an arbitrary i , assuming S1to be correct

[InductionHypothesis]

establishes Si+1 tobe correct

[Induction Step]

I Conclude ∀i . Si is true

Page 79: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Dominoes and Mathematical Induction

Domino Principle

I Infinite sequence ofdominoes

I Knock the 0th domino

I Arrange dominoes suchthat knocking one willknock the next one

I Conclude all dominoesfall

Induction Principle

I Infinite sequence of statementsS0, S1, . . .

I Prove S0 is correct [Base Case]

I For an arbitrary i , assuming S1to be correct

[InductionHypothesis]

establishes Si+1 tobe correct

[Induction Step]

I Conclude ∀i . Si is true

Page 80: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Dominoes and Mathematical Induction

Domino Principle

I Infinite sequence ofdominoes

I Knock the 0th domino

I Arrange dominoes suchthat knocking one willknock the next one

I Conclude all dominoesfall

Induction Principle

I Infinite sequence of statementsS0, S1, . . .

I Prove S0 is correct [Base Case]

I For an arbitrary i , assuming S1to be correct [InductionHypothesis] establishes Si+1 tobe correct [Induction Step]

I Conclude ∀i . Si is true

Page 81: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Dominoes and Mathematical Induction

Domino Principle

I Infinite sequence ofdominoes

I Knock the 0th domino

I Arrange dominoes suchthat knocking one willknock the next one

I Conclude all dominoesfall

Induction Principle

I Infinite sequence of statementsS0, S1, . . .

I Prove S0 is correct [Base Case]

I For an arbitrary i , assuming S1to be correct [InductionHypothesis] establishes Si+1 tobe correct [Induction Step]

I Conclude ∀i . Si is true

Page 82: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Induction ProofsAn Example

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.We will prove this by induction.

I Let Si be “δ(q, uv) = δ(δ(q, u), v) when |v | = i”

I Observe that if Si is true for all i then δ(q, uv) = δ(δ(q, u), v)for every u and v ··→

Page 83: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Induction ProofsAn Example

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.We will prove this by induction.

I Let Si be “δ(q, uv) = δ(δ(q, u), v) when |v | = i”

I Observe that if Si is true for all i then δ(q, uv) = δ(δ(q, u), v)for every u and v ··→

Page 84: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Induction ProofsAn Example

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.We will prove this by induction.

I Let Si be “δ(q, uv) = δ(δ(q, u), v) when |v | = i”

I Observe that if Si is true for all i then δ(q, uv) = δ(δ(q, u), v)for every u and v ··→

Page 85: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Induction ProofsAn Example

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.We will prove this by induction.

I Let Si be “δ(q, uv) = δ(δ(q, u), v) when |v | = i”I Observe that if Si is true for all i then δ(q, uv) = δ(δ(q, u), v)

for every u and v ··→

Page 86: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofBase Case

Proof (contd).

To establish S0, i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = 0”

I If |v | = 0 then v = ε

I Observe uε = u

I Thus, LHS = δ(q, uε) = δ(q, u)

I Observe by definition of δ(·, ·), for any q′, δ(q′, ε) = q′

I Thus, RHS = δ(δ(q, u), ε) = δ(q, u) ··→

Page 87: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofBase Case

Proof (contd).

To establish S0, i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = 0”

I If |v | = 0 then v = ε

I Observe uε = u

I Thus, LHS = δ(q, uε) = δ(q, u)

I Observe by definition of δ(·, ·), for any q′, δ(q′, ε) = q′

I Thus, RHS = δ(δ(q, u), ε) = δ(q, u) ··→

Page 88: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1.

WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 89: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1.

WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 90: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1. WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 91: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1. WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 92: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1. WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 93: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Example Inductive ProofInduction Step

Proof (contd).

Assume Si , i.e., “δ(q, uv) = δ(δ(q, u), v) when |v | = i”. Need toestablish Si+1.

I Consider v such that |v | = i + 1. WLOG, v = wa, wherew ∈ Σ∗ with |w | = n and a ∈ Σ

δ(q, uwa) = δ(δ(q, uw), a) defn. of δ

= δ(δ(δ(q, u),w), a) ind. hyp.

= δ(δ(q, u),wa) defn. of δ

Page 94: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Conventions in Inductive Proofs

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.“We will prove by induction on |v |” is a short-hand for

“We willprove the proposition by induction. Take Si to be statement of theproposition restricted to strings v where |v | = i .” �

Page 95: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Conventions in Inductive Proofs

Proposition

For a DFA M = (Q,Σ, δ, q0,F ), and any strings u, v ∈ Σ∗ andstate q ∈ Q, δ(q, uv) = δ(δ(q, u), v).

Proof.“We will prove by induction on |v |” is a short-hand for “We willprove the proposition by induction. Take Si to be statement of theproposition restricted to strings v where |v | = i .” �

Page 96: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Properties of δ

Corollary

For a DFA M = (Q,Σ, δ, q0,F ), and any string v ∈ Σ∗, a ∈ Σ andstate q ∈ Q, δ(q, av) = δ(δ(q, a), v).

Proof.From previous proposition we have, δ(q, av) = δ(δ(q, a), v) (takingu = a).

Next,

δ(q, a) = δ(δ(q, ε), a) defn. of δ

= δ(q, a) as δ(q, ε) = q

Page 97: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Properties of δ

Corollary

For a DFA M = (Q,Σ, δ, q0,F ), and any string v ∈ Σ∗, a ∈ Σ andstate q ∈ Q, δ(q, av) = δ(δ(q, a), v).

Proof.From previous proposition we have, δ(q, av) = δ(δ(q, a), v) (takingu = a).

Next,

δ(q, a) = δ(δ(q, ε), a) defn. of δ

= δ(q, a) as δ(q, ε) = q

Page 98: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Properties of δ

Corollary

For a DFA M = (Q,Σ, δ, q0,F ), and any string v ∈ Σ∗, a ∈ Σ andstate q ∈ Q, δ(q, av) = δ(δ(q, a), v).

Proof.From previous proposition we have, δ(q, av) = δ(δ(q, a), v) (takingu = a). Next,

δ(q, a) = δ(δ(q, ε), a) defn. of δ

= δ(q, a) as δ(q, ε) = q

Page 99: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Language of Modd

Proposition

L(Modd) = {w ∈ {0, 1}∗ | w has an oddnumber of 0s and an odd number of1s}.

q0 q1

q2q3

1

1

1

1

0 0 0 0

Transition Diagram of Modd

Page 100: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Language of Modd

Proposition

L(Modd) = {w ∈ {0, 1}∗ | w has an oddnumber of 0s and an odd number of1s}.

q0 q1

q2q3

1

1

1

1

0 0 0 0

Transition Diagram of Modd

Page 101: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof about the language of Modd

It fails!

Proof.We will prove by induction on |w | that δ(q0,w) ∈ F = {q2} iff whas an odd number of 0s and an odd number of 1s.

I Base Case: When w = ε, w has an even number of 0s and aneven number of 1s and δ(q0, ε) = q0 so the observation holds.

I Induction Step w = 0u: The parity of the number of 1s in uand w is the same, and the parity of the number of 0s isopposite. And δ(q0,w) = δ(δ(q0, 0), u) = δ(q3, u)

I Need to know what strings are accepted from q3! Need toprove a stronger statement. �

Page 102: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof about the language of Modd

It fails!

Proof.We will prove by induction on |w | that δ(q0,w) ∈ F = {q2} iff whas an odd number of 0s and an odd number of 1s.

I Base Case: When w = ε, w has an even number of 0s and aneven number of 1s and δ(q0, ε) = q0 so the observation holds.

I Induction Step w = 0u: The parity of the number of 1s in uand w is the same, and the parity of the number of 0s isopposite. And δ(q0,w) = δ(δ(q0, 0), u) = δ(q3, u)

I Need to know what strings are accepted from q3! Need toprove a stronger statement. �

Page 103: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof about the language of Modd

It fails!

Proof.We will prove by induction on |w | that δ(q0,w) ∈ F = {q2} iff whas an odd number of 0s and an odd number of 1s.

I Base Case: When w = ε, w has an even number of 0s and aneven number of 1s and δ(q0, ε) = q0 so the observation holds.

I Induction Step w = 0u: The parity of the number of 1s in uand w is the same, and the parity of the number of 0s isopposite. And δ(q0,w) = δ(δ(q0, 0), u) = δ(q3, u)

I Need to know what strings are accepted from q3! Need toprove a stronger statement. �

Page 104: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof about the language of ModdIt fails!

Proof.We will prove by induction on |w | that δ(q0,w) ∈ F = {q2} iff whas an odd number of 0s and an odd number of 1s.

I Base Case: When w = ε, w has an even number of 0s and aneven number of 1s and δ(q0, ε) = q0 so the observation holds.

I Induction Step w = 0u: The parity of the number of 1s in uand w is the same, and the parity of the number of 0s isopposite. And δ(q0,w) = δ(δ(q0, 0), u) = δ(q3, u)

I Need to know what strings are accepted from q3! Need toprove a stronger statement. �

Page 105: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected Proof

Proof.We need to a stronger statement that asserts what strings areaccepted from each state of the DFA. We will prove by inductionon |w | that

(a) δ(q0,w) ∈ F iff w has odd number of 0s & odd number of 1s

(b) δ(q1,w) ∈ F iff

w has odd number of 0s & even number of 1s

(c) δ(q2,w) ∈ F iff

w has even number of 0s & even number of1s

(d) δ(q3,w) ∈ F iff

w has even number of 0s & odd number of 1s

··→

Page 106: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected Proof

Proof.We need to a stronger statement that asserts what strings areaccepted from each state of the DFA. We will prove by inductionon |w | that

(a) δ(q0,w) ∈ F iff w has odd number of 0s & odd number of 1s

(b) δ(q1,w) ∈ F iff w has odd number of 0s & even number of 1s

(c) δ(q2,w) ∈ F iff

w has even number of 0s & even number of1s

(d) δ(q3,w) ∈ F iff

w has even number of 0s & odd number of 1s

··→

Page 107: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected Proof

Proof.We need to a stronger statement that asserts what strings areaccepted from each state of the DFA. We will prove by inductionon |w | that

(a) δ(q0,w) ∈ F iff w has odd number of 0s & odd number of 1s

(b) δ(q1,w) ∈ F iff w has odd number of 0s & even number of 1s

(c) δ(q2,w) ∈ F iff w has even number of 0s & even number of1s

(d) δ(q3,w) ∈ F iff

w has even number of 0s & odd number of 1s

··→

Page 108: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected Proof

Proof.We need to a stronger statement that asserts what strings areaccepted from each state of the DFA. We will prove by inductionon |w | that

(a) δ(q0,w) ∈ F iff w has odd number of 0s & odd number of 1s

(b) δ(q1,w) ∈ F iff w has odd number of 0s & even number of 1s

(c) δ(q2,w) ∈ F iff w has even number of 0s & even number of1s

(d) δ(q3,w) ∈ F iff w has even number of 0s & odd number of 1s

··→

Page 109: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofBase Case

Proof (contd).

Consider w such that |w | = 0. Then w = ε.

I w has even number of 0s and even number of 1s

I For any q ∈ Q, δ(q,w) = q

I Thus, δ(q,w) ∈ F iff q = q3, and statements (a),(b),(c), and(d) hold in the base case. ··→

Page 110: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofBase Case

Proof (contd).

Consider w such that |w | = 0. Then w = ε.

I w has even number of 0s and even number of 1s

I For any q ∈ Q, δ(q,w) = q

I Thus, δ(q,w) ∈ F iff q = q3, and statements (a),(b),(c), and(d) hold in the base case. ··→

Page 111: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofBase Case

Proof (contd).

Consider w such that |w | = 0. Then w = ε.

I w has even number of 0s and even number of 1s

I For any q ∈ Q, δ(q,w) = q

I Thus, δ(q,w) ∈ F iff q = q3, and statements (a),(b),(c), and(d) hold in the base case. ··→

Page 112: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofBase Case

Proof (contd).

Consider w such that |w | = 0. Then w = ε.

I w has even number of 0s and even number of 1s

I For any q ∈ Q, δ(q,w) = q

I Thus, δ(q,w) ∈ F iff q = q3, and statements (a),(b),(c), and(d) hold in the base case. ··→

Page 113: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n.

Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 114: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 115: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff

δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 116: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff

u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 117: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff

w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 118: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 119: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff

δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 120: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff

u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 121: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff

w has odd number of 0s and odd number of 1s ··→

Page 122: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: part (a)

Proof (contd).

Suppose (a),(b),(c), and (d) hold for strings w of length n.Consider w = au, where a ∈ {0, 1} and u ∈ Σ∗ of length n. Recallthat δ(q, au) = δ(δ(q, a), u).

I Case q = q0, a = 0: δ(q0,w) ∈ F iff δ(q3, u) ∈ F iff u haseven number of 0s and odd number of 1s (by ind. hyp. (d))iff w has odd number of 0s and odd number of 1s

I Case q = q0, a = 1: δ(q0,w) ∈ F iff δ(q1, u) ∈ F iff u hasodd number of 0s and even number of 1s (by ind. hyp. (b))iff w has odd number of 0s and odd number of 1s ··→

Page 123: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: other parts

Proof (contd).

I Case q = q1, a = 0: δ(q1,w) ∈ F iff δ(q2, u) ∈ F iff u haseven number of 0s and even number of 1s (by ind. hyp. (c))iff w has odd number of 0s and even number of 1s

I . . . And so on for the other cases of q = q1 and a = 1, q = q2and a = 0, q = q2 and a = 1, q = q3 and a = 0, and finallyq = q3 and a = 1. �

Page 124: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Corrected ProofInduction Step: other parts

Proof (contd).

I Case q = q1, a = 0: δ(q1,w) ∈ F iff δ(q2, u) ∈ F iff u haseven number of 0s and even number of 1s (by ind. hyp. (c))iff w has odd number of 0s and even number of 1s

I . . . And so on for the other cases of q = q1 and a = 1, q = q2and a = 0, q = q2 and a = 1, q = q3 and a = 0, and finallyq = q3 and a = 1. �

Page 125: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proving Correctness of a DFA

Proof Template

Given a DFA M having n states {q0, q1, . . . qn−1} with initial stateq0, and final states F , to prove that L(M) = L, we do thefollowing.

1. Come up with languages L0, L1, . . . Ln−1 such that L0 = L

2. Prove by induction on |w |, δ(qi ,w) ∈ F if and only if w ∈ Li

Page 126: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proving Correctness of a DFA

Proof Template

Given a DFA M having n states {q0, q1, . . . qn−1} with initial stateq0, and final states F , to prove that L(M) = L, we do thefollowing.

1. Come up with languages L0, L1, . . . Ln−1 such that L0 = L

2. Prove by induction on |w |, δ(qi ,w) ∈ F if and only if w ∈ Li

Page 127: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proving Correctness of a DFA

Proof Template

Given a DFA M having n states {q0, q1, . . . qn−1} with initial stateq0, and final states F , to prove that L(M) = L, we do thefollowing.

1. Come up with languages L0, L1, . . . Ln−1 such that L0 = L

2. Prove by induction on |w |, δ(qi ,w) ∈ F if and only if w ∈ Li

Page 128: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Typical Problem

ProblemGiven a language L, design a DFA M that accepts L, i.e.,L(M) = L.

How does one go about it?

Page 129: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Typical Problem

ProblemGiven a language L, design a DFA M that accepts L, i.e.,L(M) = L.How does one go about it?

Page 130: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Methodology

I Imagine yourself in the place of the machine, reading symbolsof the input, and trying to determine if it should be accepted.

I Remember at any point you have only seen a part of theinput, and you don’t know when it ends.

I Figure out what to keep in memory. It cannot be all thesymbols seen so far: it must fit into a finite number of bits.

Page 131: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Methodology

I Imagine yourself in the place of the machine, reading symbolsof the input, and trying to determine if it should be accepted.

I Remember at any point you have only seen a part of theinput, and you don’t know when it ends.

I Figure out what to keep in memory. It cannot be all thesymbols seen so far: it must fit into a finite number of bits.

Page 132: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings containing 0

ProblemDesign an automaton that accepts all strings over {0, 1} thatcontain at least one 0.

SolutionWhat do you need to remember?

Whether you have seen a 0 so faror not!

qnoz qzer

1 0, 1

0

Automaton accepting strings with at least one 0.

Page 133: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Strings containing 0

ProblemDesign an automaton that accepts all strings over {0, 1} thatcontain at least one 0.

SolutionWhat do you need to remember? Whether you have seen a 0 so faror not!

qnoz qzer

1 0, 1

0

Automaton accepting strings with at least one 0.

Page 134: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Even length strings

ProblemDesign an automaton that accepts all strings over {0, 1} that havean even length.

SolutionWhat do you need to remember?

Whether you have seen an oddor an even number of symbols.

qe qo

0, 1

0, 1

Automaton accepting strings of even length.

Page 135: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Even length strings

ProblemDesign an automaton that accepts all strings over {0, 1} that havean even length.

SolutionWhat do you need to remember? Whether you have seen an oddor an even number of symbols.

qe qo

0, 1

0, 1

Automaton accepting strings of even length.

Page 136: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Pattern Recognition

ProblemDesign an automaton that accepts all strings over {0, 1} that have001 as a substring, where u is a substring of w if there are w1 andw2 such that w = w1uw2.

SolutionWhat do you need to remember?

Whether you

I haven’t seen any symbols of the pattern

I have just seen 0

I have just seen 00

I have seen the entire pattern 001

Page 137: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Pattern Recognition

ProblemDesign an automaton that accepts all strings over {0, 1} that have001 as a substring, where u is a substring of w if there are w1 andw2 such that w = w1uw2.

SolutionWhat do you need to remember? Whether you

I haven’t seen any symbols of the pattern

I have just seen 0

I have just seen 00

I have seen the entire pattern 001

Page 138: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Pattern Recognition Automaton

qε q0 q00 qp

1

0

1

0

0

1

0, 1

Automaton accepting strings having 001 as substring.

Page 139: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep Problem

ProblemGiven text T and string s, does s appear in T?

Naıve

Solution

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷T1 T2 T3 . . .Tn Tn+1 . . .Tt

Running time = O(nt), where |T | = t and |s| = n.

Page 140: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep Problem

ProblemGiven text T and string s, does s appear in T?

Naıve

Solution

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷T1 T2 T3 . . .Tn Tn+1 . . .Tt

Running time = O(nt), where |T | = t and |s| = n.

Page 141: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep Problem

ProblemGiven text T and string s, does s appear in T?

Naıve Solution

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷=s?︷ ︸︸ ︷

=s?︷ ︸︸ ︷T1 T2 T3 . . .Tn Tn+1 . . .Tt

Running time = O(nt), where |T | = t and |s| = n.

Page 142: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep ProblemSmarter Solution

Solution

I Build DFA M for L = {w | there are u, v s.t. w = usv}I Run M on text T

Time = time to build M + O(t)!

Questions

I Is L regular no matter what s is?

I If yes, can M be built “efficiently”?

Knuth-Morris-Pratt (1977): Yes to both the above questions.

Page 143: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep ProblemSmarter Solution

Solution

I Build DFA M for L = {w | there are u, v s.t. w = usv}I Run M on text T

Time = time to build M + O(t)!

Questions

I Is L regular no matter what s is?

I If yes, can M be built “efficiently”?

Knuth-Morris-Pratt (1977): Yes to both the above questions.

Page 144: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep ProblemSmarter Solution

Solution

I Build DFA M for L = {w | there are u, v s.t. w = usv}I Run M on text T

Time = time to build M + O(t)!

Questions

I Is L regular no matter what s is?

I If yes, can M be built “efficiently”?

Knuth-Morris-Pratt (1977): Yes to both the above questions.

Page 145: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

grep ProblemSmarter Solution

Solution

I Build DFA M for L = {w | there are u, v s.t. w = usv}I Run M on text T

Time = time to build M + O(t)!

Questions

I Is L regular no matter what s is?

I If yes, can M be built “efficiently”?

Knuth-Morris-Pratt (1977): Yes to both the above questions.

Page 146: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Knuth-Morris-Pratt (1977)

From Introduction to Algorithms by CLRS

Page 147: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Multiples

ProblemDesign an automaton that accepts all strings w over {0, 1} suchthat w is the binary representation of a number that is a multipleof 5.

SolutionWhat must be remembered?

The remainder when divided by 5.How do you compute remainders?

I If w is the number n then w0 is 2n and w1 is 2n + 1.

I (a.b + c) mod 5 = (a.(b mod 5) + c) mod 5

I e.g. 1011 = 11 (decimal) ≡ 1 mod 510110 = 22 (decimal) ≡ 2 mod 510111 = 23 (decimal) ≡ 3 mod 5

Page 148: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Multiples

ProblemDesign an automaton that accepts all strings w over {0, 1} suchthat w is the binary representation of a number that is a multipleof 5.

SolutionWhat must be remembered? The remainder when divided by 5.

How do you compute remainders?

I If w is the number n then w0 is 2n and w1 is 2n + 1.

I (a.b + c) mod 5 = (a.(b mod 5) + c) mod 5

I e.g. 1011 = 11 (decimal) ≡ 1 mod 510110 = 22 (decimal) ≡ 2 mod 510111 = 23 (decimal) ≡ 3 mod 5

Page 149: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Multiples

ProblemDesign an automaton that accepts all strings w over {0, 1} suchthat w is the binary representation of a number that is a multipleof 5.

SolutionWhat must be remembered? The remainder when divided by 5.How do you compute remainders?

I If w is the number n then w0 is 2n and w1 is 2n + 1.

I (a.b + c) mod 5 = (a.(b mod 5) + c) mod 5

I e.g. 1011 = 11 (decimal) ≡ 1 mod 510110 = 22 (decimal) ≡ 2 mod 510111 = 23 (decimal) ≡ 3 mod 5

Page 150: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Multiples

ProblemDesign an automaton that accepts all strings w over {0, 1} suchthat w is the binary representation of a number that is a multipleof 5.

SolutionWhat must be remembered? The remainder when divided by 5.How do you compute remainders?

I If w is the number n then w0 is 2n and w1 is 2n + 1.

I (a.b + c) mod 5 = (a.(b mod 5) + c) mod 5

I e.g. 1011 = 11 (decimal) ≡ 1 mod 510110 = 22 (decimal) ≡ 2 mod 510111 = 23 (decimal) ≡ 3 mod 5

Page 151: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Automaton for recognizing Multiples

q0

q1

q4

q2

q3

01

0

11

0

1

0

0

1

Automaton recognizing binary numbers that are multiples of 5.

Page 152: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

A One k-positions from end

ProblemDesign an automaton for the language Lk = {w | kth characterfrom end of w is 1}

SolutionWhat do you need to remember?

The last k characters seen so far!Formally, Mk = (Q, {0, 1}, δ, q0,F )

I States = Q = {〈w〉 | w ∈ {0, 1}∗ and |w | ≤ k}

I δ(〈w〉, b) =

{〈wb〉 if |w | < k〈w2w3 . . .wkb〉 if w = w1w2 . . .wk

I q0 = 〈ε〉I F = {〈1w2w3 . . .wk〉 | wi ∈ {0, 1}}

Page 153: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

A One k-positions from end

ProblemDesign an automaton for the language Lk = {w | kth characterfrom end of w is 1}

SolutionWhat do you need to remember? The last k characters seen so far!Formally, Mk = (Q, {0, 1}, δ, q0,F )

I States = Q = {〈w〉 | w ∈ {0, 1}∗ and |w | ≤ k}

I δ(〈w〉, b) =

{〈wb〉 if |w | < k〈w2w3 . . .wkb〉 if w = w1w2 . . .wk

I q0 = 〈ε〉I F = {〈1w2w3 . . .wk〉 | wi ∈ {0, 1}}

Page 154: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Lower Bound on DFA size

Proposition

Any DFA recognizing Lk has at least 2k states.

Proof.Let M, with initial state q0, recognize Lk and assume (forcontradiction) that M has < 2k states.

I Number of strings of length k =

2k

I There must be two distinct string w0 and w1 of length k suchthat δ(q0,w0) = δ(q0,w1). ··→

Page 155: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Lower Bound on DFA size

Proposition

Any DFA recognizing Lk has at least 2k states.

Proof.Let M, with initial state q0, recognize Lk and assume (forcontradiction) that M has < 2k states.

I Number of strings of length k = 2k

I There must be two distinct string w0 and w1 of length k suchthat δ(q0,w0) = δ(q0,w1). ··→

Page 156: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Lower Bound on DFA size

Proposition

Any DFA recognizing Lk has at least 2k states.

Proof.Let M, with initial state q0, recognize Lk and assume (forcontradiction) that M has < 2k states.

I Number of strings of length k = 2k

I There must be two distinct string w0 and w1 of length k suchthat δ(q0,w0) = δ(q0,w1). ··→

Page 157: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd)

Proof (contd).

Let i be the first position where w0 and w1 differ. Without loss ofgenerality assume that w0 has 0 in the ith position and w1 has 1.

w0

0i−1

= . . .

k︷ ︸︸ ︷

0 . . .

0i−1

w1

0i−1

= . . .︸︷︷︸i−1

1 . . .︸︷︷︸k−i

0i−1

w00i−1 6∈ Lk and w10i−1 ∈ Lk . Thus, M cannot accept bothw00i−1 and w10i−1.

··→

Page 158: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd)

Proof (contd).

Let i be the first position where w0 and w1 differ. Without loss ofgenerality assume that w0 has 0 in the ith position and w1 has 1.

w00i−1 = . . .

k︷ ︸︸ ︷0 . . . 0i−1

w10i−1 = . . .︸︷︷︸i−1

1 . . .︸︷︷︸k−i

0i−1

w00i−1 6∈ Lk and w10i−1 ∈ Lk . Thus, M cannot accept bothw00i−1 and w10i−1.

··→

Page 159: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd)

Proof (contd).

Let i be the first position where w0 and w1 differ. Without loss ofgenerality assume that w0 has 0 in the ith position and w1 has 1.

w00i−1 = . . .

k︷ ︸︸ ︷0 . . . 0i−1

w10i−1 = . . .︸︷︷︸i−1

1 . . .︸︷︷︸k−i

0i−1

w00i−1 6∈ Lk and w10i−1 ∈ Lk . Thus, M cannot accept bothw00i−1 and w10i−1. ··→

Page 160: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1) = δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction!

Page 161: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1)

= δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction!

Page 162: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1) = δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction!

Page 163: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1) = δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction!

Page 164: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1) = δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction!

Page 165: CSE 135: Introduction to Theory of Computationfaculty.ucmerced.edu/sim3/teaching/spring14/lecture_notes/lecture... · CSE 135: Introduction to Theory of Computation Sungjin Im University

Proof (contd). . . Almost there

Proof (contd).

So far, w00i−1 6∈ Ln, w10i−1 ∈ Ln, and δ(q0,w0) = δ(q0,w1).

δ(q0,w00i−1) = δ(δ(q0,w0), 0i−1) by Proposition proved

= δ(δ(q0,w1), 0i−1) by assump. on w0 and w1

= δ(q0,w10i−1) by Proposition proved

Thus, M accepts or rejects both w00i−1 and w10i−1.Contradiction! �