Вы находитесь на странице: 1из 13

COMS4236: Introduction to

Computational Complexity
Summer 2014
Mihalis Yannakakis
Lecture 2

Representation of Problems

Input, output represented as strings over a finite alphabet A


eg. A={0,1}, ASCI characters,
Size of input x =|x|, the length of string x
Recoding one alphabet into another changes the size
linearly (alphabets fixed, finite) as long as |A| 2.

Encode inputs so that we can easily determine which strings


are valid encodings and can decode them
Complexity may depend on the representation of inputs (for
example graph represented by adjacency matrix vs.
adjacency lists), but reasonable encodings intertraslatable in
polynomial time

Examples

Numbers can be represented in decimal or more usually in binary


notation 5 = 101
size(N) logN:
exponential difference between size and value of a number
Graph given by its adjacency matrix: can list it eg. by rows with a
separator between rows
1

0
0
0
0

1
0
0
1

0
1
0
0

1
0
1
0

0101;0010;0001;0100
Input string over A={0,1,;}

2
3

Adjacency matrix

Graph
Graph given by its list of nodes and edges:
1,2,3,4#(1,2),(1,4),(2,3),(3,4),(4,1) over A={0,9, (,),#,,}
or with node ids in binary: 1,10,11,100#(1,10),(1,100),(10,11),(11,100),(100,1)

Decision Problems Languages

Language over alphabet A = set of (finite) strings: L A*


Decision problem for L: Input: x A*
Output: Yes if x L, No otherwise
Every decision problem P corresponds to a language LP =
(encoding of) Yes instances of P
invalid
encodings

A*
LP

Yes
instances

No
instances

Nonvalid encodings of instances lumped with the No instances

Model of Computation: Turing Machine


Turing Machine = formal model of a computer running a
particular program
Comparison with real computers: TM is very primitive, but
memory is unlimited
Primitive difficult to program, too low level, tedious to
make it do even simple tasks
But also simple, so more feasible to analyze
Although primitive, in terms of power it is
Qualitatively as powerful as any computer: can compute
any computable function Church-Turing Thesis
Quantitatively as powerful to a first approximation: at most
polynomial slowdown Strong Church-Turing Thesis

Turing Machine with 1 tape (string)


Finite Control
head (cursor)
tape

- -

. . . .

Components of TM:
K : finite set of states
special states: s =start state, yes=accepting state,
no =rejecting state, h=halting state
S : Tape alphabet, includes special symbols:
left endmarker, - blank symbol
A : input alphabet S-{, -}
d : K-{yes,no,h}S KS{L,R,S} transition function

Turing Machine with 1 tape (string) ctd.


- d : K-{yes,no,h} S KS{L,R,S}: transition function maps
the current state and tape symbol read by the head to next
state, symbol written, direction of move of tape head (Left,
Right, Stay)
-d(q, )=(.., ,R/S) for all states q, so left endmarker is never
overwritten and head does not fall off the left end of the tape
- no move from yes, no, halting state h (convention)
-Initially: state=s, tape = input - - - ., head at
-Move in each step: According to transition function d
-Note: Tape always starts with and ends with infinite number
of blanks

Configurations of TM
1. current state
2. tape content between and blanks (a finite string)
3. head position
Can represent for example as tuple (q,u,v) where q=current
state, u=string left and under tape head, v string right of
head (without the trailing blanks )
or as a string uqv over an extended tape alphabet SK, or

Move (Yield) relation (directed graph) between configurations:


C1 C2 : TM moves in one step from C1 to C2
C1 * C2: transitive closure: TM moves in 0,1,2 or more steps
from C1 to C2

Turing Machine as a Language Recognizer


Language accepted by M is L(M)={xA* | M on input x
reaches the yes state}
Note: For xL(M) it may be that M terminates at another
state or it runs forever (Definition in book requires that it
runs forever : equivalent)
M decides a language LA* if L=L(M) and for every
x A*-L , M terminates at the no state
A language is recursive if it is decided by some TM
A language is recursively enumerable if it is accepted by
some TM
recursive languages recursively enumerable languages

Turing Machine as a Function Computer


Function computed by M: On input x, if M terminates at
yes state then M(x)=yes, if at no state then M(x)=no,
if at state h then M(x)=content of tape between the left
and the infinite set of trailing blanks
For other inputs x if any, (eg. where M runs forever)
M(x)=undefined
For functions we may have different alphabets for inputs
and outputs
A function is recursive if it is computed by some TM

Examples
L={ x{0,1}* | x has an odd number of 1s}
Method: Move right remembering in state the parity of # 1s
seen so far
States K={q0,q1,yes,no}, s=q0

q0 q0,,R

q0,0,R

q1,1,R

no, -,S

q1,,R

q1,0,R

q0,1,R

yes, -,S

q1

Transition function shown here by transition table


Can also represent by transition diagram

Example ctd
- Every regular language can be similarly decided by a TM
that moves its head from left end to the right reading the input
(state = state of a DFA that accepts the language)
odd # 1s

TM
1

DFA

- / -,S

1
0

no

q0
0

yes

1/1,R

- / -,S

q1

1/1,R
0/0,R
0/0,R
/ ,R
/ ,R

Many variations in TM definitions


Different authors often use slightly different definitions

Some variants:
Head moves left or right but does not stay in place
Machine does not ever write the blank symbol Two-way infinite tape instead of one way infinite tape
. .. .. ..

All equivalent; same computing power

Вам также может понравиться