Editing Change problem

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 4: Line 4:
 
The former, the optimization problem, should be very familiar. It is a problem that cashiers solve when (for example) you hand them a five-dollar bill for a purchase of $3.44, and they have to find a way to give you back $1.56 in ''change'', preferably with as few coins as possible.<ref>The Canadians have a $2.00 coin, a $1.00 coin, a $0.25 coin, a $0.10 coin, a $0.05 coin, and a $0.01 coin. The solution to this problem in Canadian currency is one $1.00 coin, two $0.25 coins, one $0.05 coin, and one $0.01 coin.</ref> It is a well-studied problem that is extensively treated in the literature. The counting problem is somewhat more exotic; it arises mostly as a mathematical curiosity, often in the form of the puzzle: "How many ways are there to make change for a dollar?"<ref>The denominations in circulation in the United States are the same as those in Canada, except for the absence of a $2.00 coin and the presence of a $0.50 coin. In United States currency, the answer is 293 if the trivial solution consisting of a single one-dollar coin is counted, or 292 if it is not.</ref> It is also not often encountered in the literature, but it is discussed here because it occasionally appears in algorithmic programming competitions.
 
The former, the optimization problem, should be very familiar. It is a problem that cashiers solve when (for example) you hand them a five-dollar bill for a purchase of $3.44, and they have to find a way to give you back $1.56 in ''change'', preferably with as few coins as possible.<ref>The Canadians have a $2.00 coin, a $1.00 coin, a $0.25 coin, a $0.10 coin, a $0.05 coin, and a $0.01 coin. The solution to this problem in Canadian currency is one $1.00 coin, two $0.25 coins, one $0.05 coin, and one $0.01 coin.</ref> It is a well-studied problem that is extensively treated in the literature. The counting problem is somewhat more exotic; it arises mostly as a mathematical curiosity, often in the form of the puzzle: "How many ways are there to make change for a dollar?"<ref>The denominations in circulation in the United States are the same as those in Canada, except for the absence of a $2.00 coin and the presence of a $0.50 coin. In United States currency, the answer is 293 if the trivial solution consisting of a single one-dollar coin is counted, or 292 if it is not.</ref> It is also not often encountered in the literature, but it is discussed here because it occasionally appears in algorithmic programming competitions.
  
==Discussion of complexity==
+
By dealing together, you both can address problems of self-esteem and mutual trust. Once you discover the top natural cures, you are able to again have full charge of your sexual pleasures.
The corresponding decision problem, which simply asks us to determine whether or not making change is ''possible'' with the given denominations (which it might not be, if we are missing the denomination 1) is known to be [[NP-complete]].<ref>G. S. Lueker. (1975). ''Two NP-complete problems in nonnegative integer programming.'' Technical Report 178, Computer Science Laboratory, Princeton University. (The authors were not able to obtain a copy of this paper, but in the literature it is invariably cited to back up the claim that change is NP-complete.)</ref> It follows that the optimization and counting problems are both [[NP-hard]] (''e.g.'', because the result of 0 for the counting problem answers the decision problem in the negative, and any nonzero value answers it in the affirmative).
+
 
+
However, as we shall see, a simple <math>O(nT)</math> solution exists for both versions of the problem. Why then are these problems not in P? The answer is that the ''size'' of the input required to represent the number <math>T</math> is actually the ''length'' of the number <math>T</math>, which is <math>\Theta(\log T)</math> when <math>T</math> is expressed in binary (or decimal, or whatever). Thus, the time and space required by the algorithm is actually <math>O(n 2^{\lg T})</math>, that is, exponential in the size of the input. (This simplified analysis does not take into account the sizes of the denominations, but captures the essence of the argument.) This algorithm is then said to be ''pseudo-polynomial''. No true polynomial-time algorithm is known (and, indeed, none will be found unless it turns out that P = NP).
+
  
 
==Greedy algorithm==
 
==Greedy algorithm==

Please note that all contributions to PEGWiki are considered to be released under the Attribution 3.0 Unported (see PEGWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, 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. Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)