Docsity

Complexity Classes and Algorithm Analysis in Computer Science - Prof. David Evans, Study notes of Discrete Mathematics

Toggle sidebar
bg1
1
Class 22:
Class 22:
Classy
Classy
Complexity
Complexity
Classes
Classes
David Evans
David Evans
http://www.cs.virginia.edu/evans
http://www.cs.virginia.edu/evans
cs302: Theory of Computation
cs302: Theory of Computation
University of Virginia Computer Science
University of Virginia Computer Science
Office hours
note: my office
hours tomorrow
will be 10-11am
in my office.
PS6 (the last one) is posted now and will be
due Thursday, April 24.
2
Lecture 22: Classy Complexity Classes
Menu
• Why 2150?
• Asymptotic Analysis
• Mind vs. Turing Machine (from PS5)
• Complexity Class P
• Complexity Class NP
3
Lecture 22: Classy Complexity Classes
Computability Complexity
Decidable
Undecidable
~1800s – 1960s
1900: Hilbert’s Problems
1936: Turing’s Computable Numbers
1957: Chomsky’s Syntactic Structures
(Mostly) “Dead” field
Intractable
Tractable
1960s – 2150?
1960s: Hartmanis and
Stearns: Complexity class
1971: Cook/Levin, Karp: P=NP?
1976: Knuth’s O, Ω, Θ
Very Open and Alive
From last class:
4
Lecture 22: Classy Complexity Classes
Predicting Knowledge
• In golden age fields, knowledge doubles every 15
years (read Neil DeGrasse Tyson’s Science’s
Endless Golden Age)
• Hence, in 2158, we should know ~1024 times (10
doublings) what we know today
• So, guessing it will end in ~2150 implies:
– Computational Complexity is a finite field
– What we know today is about 1/1000th what there is
I don’t know if either of these is true, but they se em like reasonable guesses...
5
Lecture 22: Classy Complexity Classes
Asymptotic Notation Recap
• Big-O: f ∈O(g): no faster than
if there exist c, n0> 0 such that
f(n) ≤
≤≤
≤cg(n)for all n≥n0.
• Omega: f∈Ω(g): no slower than
if there exist c, n0> 0 such that
f(n) ≥
≥≥
≥cg(n)for all n≥n0.
• Theta: f ∈Θ(g) iff f ∈O(g) and f∈Ω(g)
Little-o:
<instead of ≤
≤≤
≤
6
Lecture 22: Classy Complexity Classes
Algorithm Analysis
• What is the asymptotic running time of the
Java-ish procedure below:
int gaussSum (int m) {
int sum = 0;
for (int i = 1; i <= m; i++) {
sum = sum + i;
}
return sum;
}
Good “cs201/cs216” answer:
Θ(n)
What does this mean?
What does it assume?
pf3
pf4
pf5

Partial preview of the text

Download Complexity Classes and Algorithm Analysis in Computer Science - Prof. David Evans and more Study notes Discrete Mathematics in PDF only on Docsity!

Class 22: Class 22:

ClassyClassy

Complexity Complexity

ClassesClasses

David Evans David Evans http://www.cs.virginia.edu/evans http://www.cs.virginia.edu/evans

cs302: Theory of Computationcs302: Theory of Computation University of Virginia Computer ScienceUniversity of Virginia Computer Science

Office hours note: my office hours tomorrow will be 10-11am in my office.

PS6 (the last one) is posted now and will be due Thursday, April 24.

Lecture 22: Classy Complexity Classes 2

Menu

  • Why 2150?
  • Asymptotic Analysis
  • Mind vs. Turing Machine (from PS5)
  • Complexity Class P
  • Complexity Class NP

Lecture 22: Classy Complexity Classes 3

Computability Complexity

Decidable

Undecidable

~1800s – 1960s 1900: Hilbert’s Problems 1936: Turing’s Computable Numbers 1957: Chomsky’s Syntactic Structures

(Mostly) “Dead” field

Intractable

Tractable

1960s – 2150? 1960s: Hartmanis and Stearns: Complexity class 1971: Cook/Levin, Karp: P=NP? 1976: Knuth’s O , Ω, Θ Very Open and Alive

From last class:

Lecture 22: Classy Complexity Classes 4

Predicting Knowledge

  • In golden age fields, knowledge doubles every 15

years (read Neil DeGrasse Tyson’s Science’s

Endless Golden Age)

  • Hence, in 2158, we should know ~1024 times (

doublings) what we know today

  • So, guessing it will end in ~2150 implies:
    • Computational Complexity is a finite field
    • What we know today is about 1/1000th^ what there is I don’t know if either of these is true, but they seem like reasonable guesses...

Lecture 22: Classy Complexity Classes 5

Asymptotic Notation Recap

  • Big-O: f ∈ O ( g ): no faster than

if there exist c , n 0 > 0 such that

f ( n ) ≤≤≤≤ cg ( n ) for all n ≥ n 0.

  • Omega: f ∈ Ω( g ): no slower than

if there exist c , n 0 > 0 such that

f ( n ) ≥≥≥≥ cg ( n ) for all n ≥ n 0.

  • Theta: f ∈ Θ( g ) iff f ∈ O ( g ) and f ∈ Ω( g )

Little-o: < instead of ≤≤≤≤

Lecture 22: Classy Complexity Classes 6

Algorithm Analysis

  • What is the asymptotic running time of the

Java-ish procedure below:

int gaussSum (int m) { int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + i; } return sum; }

Good “cs201/cs216” answer: Θ( n )

What does this mean? What does it assume?

Lecture 22: Classy Complexity Classes 7

Algorithm Analysis

  • gaussSum is order n : “A function that outputs

the running time of gaussSum when the input

is the value of the input is in Θ( n ).

int gaussSum (int m) { int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + i; } return sum; }

Assumes: m is unbounded (not true for real Java)

  • is constant time (not true if m is unbounded) Note that these assumptions are mutually inconsistent so the answer is “wrong” (but useful). Lecture 22: Classy Complexity Classes 8

“Correct”ish Answers

int gaussSum (int m) { int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + i; } return sum; }

Assume m is bounded (e.g., 32-bit integer as in real Java). Then, running time of gaussSum is in O (1).

Assume m is unbounded. Then, the average running time of the + is in Θ(log m ), so the running time of gaussSum is in Θ( m log m ).

Lecture 22: Classy Complexity Classes 9

What are we really measuring?

  • Input size: number of tape squares it takes to

write down the input

  • Running time: number of steps it takes before

TM enters a final state

  • Input size for gaussSum = log m
    • Number of bits to represent m (not its magnitude)
    • Note: if we used unary it would be size m

Why doesn’t log base matter in asymptotic notations?

Lecture 22: Classy Complexity Classes 10

Most Correct Answer

int gaussSum (int m) { int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + i; } return sum; }

Assume the size of the input N is unbounded. Then, m ~ 2 N. The running time of + is in Θ(log m ) = Θ( N ) so the running time of gaussSum is in ΘΘΘΘ (2 NN ) = where N is the size of the input.

Is ΘΘΘΘ (2 NN ) = ΘΘΘΘ (2 N )? Left as small challenge problem (everyone should be able to answer this using definition of ΘΘΘΘ.)

Lecture 22: Classy Complexity Classes 11

Algorithm Analysis

int gaussSum (int m) { int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + i; } return sum; } cs201/cs216 answer: Θ( n ) where n is the value of the input

cs302 answer: in ΘΘΘΘ (2 NN ) where N is the size of the input.

cs432 answer: don't analyze Java code, analyze idealized pseudocode and state assumptions clearly. Lecture 22: Classy Complexity Classes 12

gaussSum Problem

  • So, what is the time complexity of the

gaussSum problem?

Input: a positive integer m

Output: sum of the integers from 1 to m.

From the previous analysis, we know an algorithm that solves it with running time in ΘΘΘΘ ( N 2 N ).

This means the time complexity of the problem is in O ( N 2 N ). But it does not give a tight bound.

Lecture 22: Classy Complexity Classes 19

Self-Modification

  • "… Humans can even learn enough from the

world around them to alter their own

programming."

  • "…a TM cannot adapt, and has no way to

change its own rules or states."

Recall a Universal TM can simulate every other TM. So, it is certainly possible for a TM to simulate a TM that changes rules and states in response to the input.

Lecture 22: Classy Complexity Classes 20

Self-Awareness

Humans are more "cognizant" of their shortcomings than TMs. There are several problems that humans understand are impossible to answer, but no TM can simulate the decision that any of these problems are decidedly unsolvable. David Horres

I can't help but quote from South Park: "You see, the basis of all reasoning is the mind's awareness of itself. What we think, the external objects we perceive, are all like actors that come on and off stage. But our consciousness, the stage itself, is always present to us." (Kyle) Hung-in Lam

Lecture 22: Classy Complexity Classes 21

Memory Access

Our brains have the ability to recognize patterns and then use those patterns to filter new data. Since our brains store memories primarily through association rather than just memory addresses, this allows for an integrated, relational system of memories…. Our memories "fade" over time, yet can occasionally be brought back… Eric Montgomery

Lecture 22: Classy Complexity Classes 22

Real Time/World Interactions

A mind can interact with physical inputs and outputs in real time. The brain is able to make decisions in real time; either a synapse fires or it doesn't. What would happen in a brain model that waited forever for a single binary decision? Would the brain-simulating TM ever be able to make all the decisions necessary for even the tiniest slice of time? Such a TM would probably be eaten by a hungry woof; how embarrassing for such a smart machine! Rachel Miller

"ability to interact with the surrounding environment"

Lecture 22: Classy Complexity Classes 23

…ability of the human mind to process analog

inputs. The possible ranges for sound or light

are infinite, and are not stored digitally in the

brain. …

Chris Dodge

Some physicists think space-time can be quantized at about 10-23^ meters and 10-32^ seconds. So, in theory a TM could process analog inputs, but in practice all the atoms in the universe would not be enough to make the tape for the TM…

Lecture 22: Classy Complexity Classes 24

Resilience

"The brain can function without some of its components, but a TM cannot…." Jalysa Conway

"The human mind is also capable of breaking out of an infinite loop that a TM would be stuck in forever… a person gets bored, something that no TM can emulate. " Timothy Kang

Lecture 22: Classy Complexity Classes 25

Neurons tend to fire in a synchronized way. A group of neurons in one part of the brain, for example, may light up at the same time and cause another group to activate in another region. Finally, neurons are capable of neurogenesis, the creation of new brain cells. A TM, no matter how much use it gets, will always remain a TM. The brain, however, is a muscle that is influenced by many factors, including usage. In fact, even the eldest of living humans can avoid mental breakdown by simply exercising their brains frequently… Christopher Andersen Note: exercising your brain is a good idea for young humans also!

Lecture 22: Classy Complexity Classes 26

Would it be useful to have a

computational problem that

humans can solve

but computers cannot solve?

link link

Lecture 22: Classy Complexity Classes 27

Thwarting

Spammers,

Annoying

Humans

CAPTCHA: Completely Automated Public Turing

Test to Tell Computers and Humans Apart

Luis von Ahn, Manuel Blum and John Langford. Telling Humans and Computers Apart Automatically. Lecture 22: Classy Complexity Classes 28

Complexity Class P

Lecture 22: Classy Complexity Classes 29

Non-Robustness of TM Complexity

  • Computability: all variations on TMs have the

same computing power

  • If there is a multi-tape TM that can decide L , there is a regular TM that can decide L.
  • If there is a nondeterministic TM that can decide L , there is a deterministic TM that can decide L.
  • Complexity: variations on TM can solve

problems in different times

  • Is a multi-tape TM faster than a regular TM?
  • Is a nondeterministic TM faster than a regular TM? Lecture 22: Classy Complexity Classes 30

Multi-Tape vs. One-Tape TM

Are there problems that are in

TIME ( t ( n )) for a multi-tape TM, but

not in TIME ( t ( n )) for a one-tape TM?