Editing 287: NP-Complete

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 7: Line 7:
 
}}
 
}}
  
==Explanation==
+
== Explanation ==
Another entry in the [[:Category:My Hobby|My Hobby series]]. [[Cueball]] is embedding {{w|NP-complete|NP-complete problems}} in restaurant orders. Specifically, he is ordering appetizers not by explicitly stating the names, but by the total price of them all. This is a simplified example of the {{w|Knapsack problem|knapsack problem}}. This is a problem in combinatorial optimization, as follows: If you have a knapsack (backpack or rucksack) that can hold a specific amount of weight, and you have a set of items, each with its own assigned value and weight, you have to select items to put into the knapsack so that the weight does not exceed the capacity of the knapsack, and the combined value of all the items is maximized.
+
Another entry in the “My Hobby” series of cartoons; here, [[Cueball]] is embedding NP-complete problems in restaurant orders. Specifically, he is ordering appetizers not by explicitly stating the names of the appetizers, but by the total price of the chosen appetizers. This is a (simplified) example of the knapsack problem. The [[wikipedia:Knapsack problem|knapsack]] (or rucksack) problem is a problem in combinatorial optimization, as follows: if you have a knapsack (or backpack, or rucksack, as your regional desire to call it may be) which can hold a specific amount of weight, and you have a set of items, each with its own assigned value and weight, can you select items to put into the knapsack so that (1) the weight does not exceed the capacity of the knapsack, and (2) the combined value of all the items is maximized. (The example in this cartoon is simplified, because we are not given the corresponding “value” of each item – like we would be if, for example, Cueball and his two friends assigned a perceived value of 7 on a scale of 1 to 10 for getting hot wings, but only a 2 out of 10 for a side salad. Another way to introduce complexity into the problem would be if the patrons were considering the calorie values of each appetizer on the menu.)
  
In {{w|Computational complexity theory|computational complexity theory}}, NP stands for "nondeterministic polynomial time," which means that problems that are NP take polynomial running time (i.e. the time a CPU would take to run the program would be polynomial in the input size) to verify a solution, but it is unknown whether finding any or all solutions can be done in polynomial time. Polynomial time is considered efficient; exponential and higher times are considered unfeasible for computation. NP-complete problems are ones that, if a polynomial time algorithm is found for any of them, then all NP problems have polynomial time solutions. In short, particular guesses in NP-complete problems can be checked easily, but systematically finding solutions is far more difficult.
+
The knapsack problem is, as indicated by the title of the strip, [[wikipedia:NP-complete|NP-complete.]] In computational complexity theory, NP stands for “nondeterministic polynomial time.” Basically, for an NP-complete problem, there is no efficient way to find a solution, but it is relatively easy to verify that a solution works. Conceptually, for the problem posed in this comic, the most straightforward way to find a solution (not even knowing for certain if there is one) is to methodically start by first listing all the (6) ways of choosing one appetizer, and their totals (which of course are the prices of each appetizer), then list all the (21) ways of choosing two appetizers (allowing the same appetizer to be chosen twice, since we are assuming that the chef can create more than one sampler platter), and then list all the (56) ways of choosing three appetizers, and so forth. As any combination of eight appetizers would be more than $15.05, the process need not extend beyond listing all the (1715) ways of choosing seven appetizers.
  
The waiter's problem is NP-complete, since a given order's price can be found and checked quickly, but finding an order to match a price is much harder. This causes the order to effectively be an {{w|application layer}} {{w|denial-of-service attack}} / {{w|algorithmic complexity attack}} on the waiter, similar to {{w|Slowloris (computer security)|Slowloris}} or {{w|ReDoS}}. (Formal proofs of the NP-completeness of the knapsack problem can be found at the above link.) The most straightforward way for a human to find a solution is to methodically start by first listing all the (6) ways of choosing one appetizer, and their total costs, then list all the (21) ways of choosing two appetizers (allowing repeats), and then list all the (56) ways of choosing three appetizers, and so forth. As any combination of eight appetizers would be more than $15.05, the process need not extend beyond listing all the (1715) ways of choosing seven appetizers.
+
The image text refers to the fact that NP-complete problems have no known general solution. (A general solution would be the optimal solution to this problem generalized to allow any prices for the appetizers.) If the waiter can find an efficient general solution to this, or any NP-complete problem, he will have solved one of the most famous problems in computer science, whether or not P=NP. In other words, if every problem whose solution can be quickly verified by a computer can also be quickly solved by a computer. This problem is one of the seven [[wikipedia:Millennium Prize Problems|Millennium Prize Problems]] stated by the Clay Institute in 2000, six of which (including whether P=NP) are still unsolved, for which a correct solution is worth US$1,000,000, so a 50% tip is slightly less than fair.
  
Another famous NP-complete problem is the {{w|Travelling salesman problem|travelling salesman problem}}, mentioned by Cueball at the end, referring to the waiter's claim that he has 6 more tables to get to. (see also [[399: Travelling Salesman Problem]]).
+
Another famous NP-complete problem is the [[wikipedia:Travelling salesman problem|Travelling Salesman problem]] (also see [[399: Travelling Salesman Problem]]), also mentioned in the strip. An example: suppose a traveling salesman has to visit ten cities and then return home, and it is possible to directly travel from any city to any other city (by plane, for example.) What is the minimum distance (or time, or cost) necessary for the trip? Like the knapsack problem, it is (usually) difficult to find the best solution without trying a very large number of combinations. Cueball mentions this problem after the waiter states he has to tend to six other tables.
  
The title text refers to the fact that NP-complete problems have no known polynomial time general solutions, and it is unknown if such a solution can ever be found. If the waiter can find an efficient general solution to this, he will have solved one of the most famous problems in mathematics. This problem is one of the six remaining unsolved {{w|Millennium Prize Problems}} stated by the Clay Mathematics Institute in 2000, for which a correct solution (including proving that such a solution doesn't exist) is worth US$1,000,000. A 50% tip is slightly less than fair.{{cn}}
+
A film reference is embedded in the menu in the first panel: the restaurant is called “Chotchkies,a fictional restaurant featured in the film [[wikipedia:Office Space|Office Space]]. (In that film, the character Joanna, played by [[wikipedia:Jennifer Aniston|Jennifer Aniston]], quits her job at Chotchkies, a typical family-oriented chain restaurant, over their policy that she wear a large number of “flair” items – tacky pins, buttons, or other adornments to a worker’s uniform which can often be seen on waiters and waitresses at chain family restaurants, as well as those who work at movie theaters or large retail chain stores.)
  
For those curious, there are exactly two combinations of appetizers that total $15.05 and solve the problem posed in the comic strip:
+
== Solution ==
#A combination of two orders of hot wings, one order of mixed fruit, and one sampler plate
+
There are exactly two solutions to the problem posed in the comic strip, combinations of appetizers which total $15.05:
#Seven mixed fruit orders (this solution was not intended - see [[#Trivia|trivia]] below)
+
* seven mixed fruit orders
 +
* a combination of two orders of hot wings, one order of mixed fruit, and one sampler plate
  
 
==Transcript==
 
==Transcript==
Line 26: Line 27:
 
:Embedding NP-Complete problems in restaurant orders
 
:Embedding NP-Complete problems in restaurant orders
 
:[A menu is shown.]
 
:[A menu is shown.]
:'''Chotchkies Restaurant'''
+
:Chotchkies Restaurant
 
:Appetizers
 
:Appetizers
::Mixed Fruit 2.15
+
:Mixed Fruit 2.15
::French Fries 2.75
+
:French Fries 2.75
::Side Salad 3.35
+
:Side Salad 3.35
::Hot Wings 3.55
+
:Hot Wings 3.55
::Mozzarella Sticks 4.20
+
:Mozzarella Sticks 4.20
::Sampler Plate 5.80
+
:Sampler Plate 5.80
:Sandwiches
+
:[Three people sit at a table, including Cueball who is ordering from a waiter.]
::Barbecue 6.55
 
:[Megan, another person, and Cueball are sitting at a table. Cueball is holding the menu as well as a thick book and is ordering from a waiter. Megan is facepalming.]
 
 
:Cueball: We'd like exactly $15.05 worth of appetizers, please.
 
:Cueball: We'd like exactly $15.05 worth of appetizers, please.
:Waiter: ...Exactly? Uhh...
+
:Waiter: ... Exactly? Uhh ...
 
:Cueball: Here, these papers on the knapsack problem might help you out.
 
:Cueball: Here, these papers on the knapsack problem might help you out.
:Waiter: Listen, I have six other tables to get to—
+
:Waiter: Listen, I have six other tables to get to -
:Cueball: —As fast as possible, of course. Want something on traveling salesman?
+
:Cueball: - As fast as possible, of course. Want something on traveling salesman?
  
==Trivia==
+
{{Comic discussion}}
 
 
*"Chotchkies" (slightly misspelt) is Yiddish slang for little accessories and trinkets. It is also the name of the restaurant in the 1999 Mike Judge-directed comedy ''{{w|Office Space}}''.
 
 
 
*In [http://www.maa.org/mathhorizons/MH-Sep2012_XKCD.html an interview] with the Mathematical Association of America, Randall said that the trivial answer to this problem was a mistake. <br/> Randall explains in ''[[xkcd: volume 0]]'' that this was due to him using a Perl script with a bug ("You can't compare IEEE floats for equality").
 
 
 
{{comic discussion}}
 
 
[[Category:Comics featuring Cueball]]
 
[[Category:Comics featuring Cueball]]
 
[[Category:My Hobby]]
 
[[Category:My Hobby]]
 
[[Category:Comics with color]]
 
[[Category:Comics with color]]
[[Category:Math]]
 
[[Category:Programming]]
 

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)