P, NP, and NP-Complete Problems - PowerPoint PPT Presentation

About This Presentation
Title:

P, NP, and NP-Complete Problems

Description:

P, NP, and NP-Complete Problems Section 10.3 Our Favorite Example Djikstra s Shortest Path Algorithm Nondeterministic Computers Seem More powerful Than ... – PowerPoint PPT presentation

Number of Views:150
Avg rating:3.0/5.0
Slides: 16
Provided by: cseLehigh
Category:

less

Transcript and Presenter's Notes

Title: P, NP, and NP-Complete Problems


1
P, NP, and NP-Complete Problems
  • Section 10.3

2
The class P consists of all problems that can be
solved in polynomial time, O(Nk), by
deterministic computers (the ones that you have
used all your life!). Examples
  • Adding two numbers
  • Extracting the element with the highest priority
    from a heap
  • Looking for an element in an array
  • Looking for the MST

O(1) constant
O(log N) logarithmic (thus, O(N) because N ?
log N )
O(N) lineal
O(N log N) (thus, O(N2) )
3
What does Deterministic Computer Means?(Idea)
(For details see CSE 318)
At every computational cycle we have the
so-called state of the computation
3. Program ltinstructiongt .
State (1. memory, 2. location of memory being
pointed at, 3. program, 4. current
instruction)
4
What does Deterministic Computer Means?(Idea- II)
In a deterministic computer we can determine in
advance for every computational cycle, the output
state by looking at the input state
Computer Memory
Program ltinstructiongt .
5
Our Favorite Example
//input an array A1..N and an element el that
is in the array //output the position of el in A
search(el, A, i) if (Ai el) then return
i else return search(el, A, i1)
Complexity O(N)
6
Djikstras Shortest Path Algorithm
D
3
B
2
6
E
A
3
4
C
H
If the source is A, which edge is selected in the
next iteration?
Complexity O(N log N) ( N number of edges
vertices)
7
What does NonDeterministic Computer Means?
In a nondeterministic computer we may have more
than one output state.
Computer Memory
Program ltinstructiongt .
The computer chooses the correct one
(nondeterministic choice)
8
Nondeterministic Computers Seem More powerful
Than Deterministic Ones
Informally Calls an Oracle who makes the right
choice
nonDeterministicSearch(el, A) return
i
i ? ohOracle(el, A, 1)
9
But They Are Not More Powerful
ohOracle(el, A, i) if (Ai el) then
return i else return ohOracle(el, A,
i1)
nonDeterministicSearch(el, A) i ?
ohOracle(el, A, 1) return i
Key result Every program for a nondeterministic
computer can be simulated by a deterministic one
(CSE 318)
Thus, they solve the same problems
10
But What About the Complexity?
search(el, A, i, N) if (Ai el) then
return i else return search(el, A,
i1,N)
OracleSearch(el, A, N) i ? Oracle(el, A,
N) return i
Complexity O(N)
Complexity O(1)
11
Formal Definition Nondeterministic Algorithms
A nondeterministic algorithm for a problem A is a
two-stage procedure. In the first phase, a
procedure makes a guess about the possible
solution for A. In the second phase, a procedure
checks if the guessed solution is indeed a
solution for A
Phase2(i,el, A) return
Phase1(el, A) return i
i ? random(1..N)
Ai el
Note the actual solution must be included among
the possible guesses of phase 1
12
NP Complexity
The class NP consists of all problems that can be
solved in polynomial time by nondeterministic
algorithms
(that is, both phase 1 and phase 2 run in
polynomial time)
If A is a problem in P then A is a problem in NP
because
Phase 1 use the polynomial algorithm that solves
A Phase 2 write a constant time procedure that
always returns true
The key question is are there problems in NP that
are not in P or is P NP?
We dont know the answer to the previous question
13
NP Complexity (II)
How to proof that a problem A is in NP
  • 1. Show that A is in P, or
  • 2. Write a nondeterministic algorithm solving A
    that runs in polynomial time

14
Example
Showing that searching for an element in an array
is in P
  • 1. Write the procedure search(el, A, i) (Slide 5)
    which runs in lineal time, or
  • 2. Write a non-deterministic algorithm solving
    search (Slide 11 both Phase 1 and Phase 2 run in
    constant time)

15
Homework
  • Both sections write a nickname so I can post
    your grades on the web and you remain anonym
  • Section 010
  • Section 9.4 3.b, 4, 6
  • Construct a nondeterministic algorithm computing
    the MST for an input graph (pseudocode). For
    phase 2 assume that the minimum cost is known in
    advance. What is the complexity of this
    algorithm?
  • Construct a nondeterministic algorithm solving
    the traveling salesman person problem
    (pseudocode). For phase 2 assume that the minimum
    cost is known in advance. What is the complexity
    of this algorithm?
  • Section 011
  • Section 9.4 3.a, 5.a, 5.b
  • Construct a nondeterministic algorithm computing
    the shortest path from a node u to a node v in an
    input graph (pseudocode). For phase 2 assume that
    the minimum cost is known in advance. What is the
    complexity of this algorithm?
  • Construct a nondeterministic algorithm solving
    the Knapsack problem (pseudocode). For phase 2
    assume that the minimum cost is known in advance.
    What is the complexity of this algorithm?
Write a Comment
User Comments (0)
About PowerShow.com