567 Hafta 9 1
567 Hafta 9 1
Lower Bounds
Limitations of Examples:
Algorithm Power number of comparisons needed to find the largest element
in a set of n numbers
number of comparisons needed to sort an array of size n
number of comparisons necessary for searching in a sorted
array
number of multiplications needed to multiply two n-by-
by-n
matrices
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-3 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-4
element uniqueness
abc bac
yes no yes no
Hamiltonian circuit existence b< c a<c
be careful in deciding how many elements must be processed a<c<b c<a<b b<c<a c<b<a
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-5 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-6
1
Design and Analysis of Algorithms Chapter 9
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-7 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-8
unknown
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-9 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-10
Decision problem:
problem: answer yes/no to a question Examples:
searching
Many problems have decision and optimization versions.
element uniqueness
E.g.: traveling salesman problem
optimization:: find Hamiltonian cycle of minimum length
optimization graph connectivity
decision:: find Hamiltonian cycle of length m
decision
graph acyclicity
Decision problems are more convenient for formal investigation of
their complexity. primality testing (finally proved in 2002)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-11 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-12
2
Design and Analysis of Algorithms Chapter 9
This problem is in NP
NP.. Nondeterministic algorithm:
A nondeterministic polynomial algorithm is an abstract two-
two-stage
procedure that: Guess truth assignment
generates a random string purported to solve the problem Substitute the values into the CNF formula to see if it
evaluates to true
checks whether this solution is correct in polynomial time
By definition, it solves the problem if it’s capable of generating and Example: (A | ¬B | ¬C
¬C)) & (A | B ) & (¬ B | ¬D | E ) & (¬D | ¬E)
¬E )
verifying a solution on one of its tries Truth assignments:
ABCDE
0 0 0 0 0
Why this definition? . . .
led to development of the rich theory called “computational 1 1 1 1 1
complexity” Checking phase: O(n)
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-13 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-14
P NP
Big question: P = NP ?
Cook’s theorem (1971): CNF
CNF--sat is NP
NP--complete
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-15 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-16
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-17 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2nd ed., Ch. 11 11-18