January 28, 2009
Managing a Bestiary of Algorithms:
Complexity Classes and NP-Completeness
Thanks to Maggie Johnson for some portions of this handout.
A Quick Introduction to NP-Completeness
Imagine that you have decided to go on a skiing adventure across the Sierras.
Since there are no
McDonalds between Yosemite and Lee Vining, you will need to bring all your food with you in
your pack (um, yes, did I forget to mention that you are
across the Sierras?!).
this trip, taste is a secondary consideration.
What matters is how much your food weighs and
how many calories it contains.
After raiding your kitchen (or your dorm dining hall), you
discover that you have roughly 200 different food items.
Each item has a certain weight and
contains a certain number of calories:
200. Dry Spaghetti
Given this selection of food, your task is to find the best subset that maximizes the number of
calories, but falls within the weight limit you can carry in your pack (say 15kg).
that definitely produces a solution is to simply try every possible combination.
there are 2
such combinations, and the Sierras would erode away before that algorithm
Always a bummer when that happens.
Is there another algorithm that runs in reasonable time (
., a polynomial, as opposed to
exponential, number of steps in the size of the input)?
If there is, no one has found it yet.
might make you suspect that no polynomial time solution exists, but no one has ever been able to
prove that either.
This problem, known as the Knapsack Problem, is an example of a general
class of problems called the
These are problems for which no
polynomial time solution currently exists, but it is unproven whether the problems necessarily
require exponential time.
In fact, there is currently a $1 million prize
for first person who can either find a polynomial
time solution to an NP-complete problem, or prove that such a problem can only be solved with
an exponential time algorithm.
Sounds like something to consider as a summer project…
Characterizing Function Growth Rates
In studying algorithms, we have seen functions and big-Oh notation used to characterize the
running time of algorithms.
There are some important terms used to classify problems, based on
“P vs. NP” problem is one of seven “Millennium Prize Problems” that have been named by The Clay
Mathematics Institute (CMI) of Cambridge, Massachusetts as worthy of a $1 million prize.
You may find more