On the Change-Making Problem

Total Page:16

File Type:pdf, Size:1020Kb

On the Change-Making Problem On the Change-Making Problem Timothy M. Chan∗ Qizheng He∗ Abstract (There are a number of other interesting problems Given a set of n non-negative integers representing a coin related to coin systems, such as the Frobenius problem, system, the change-making problem seeks the fewest number but these are not relevant to the present paper.) of coins that sum up to a given value t, where each Partially spurred by a renewed interest in fine- type of coin can be used an unlimited number of times. grained complexity, there have been a flurry of re- This problem is a popular homework exercise in dynamic cent works that improve upon the standard O(nt) so- programming, where the textbook solution runs in O(nt) lution for the subset sum problem,p starting with Koil- time. iaris and Xu's deterministic O( nt polylog t)-time al- It is not hard to solve this problem in O(t polylog t) time gorithm [8, 9], followed by Bringmann's randomized by using convolution. In this paper, we present a simple O(t polylog t)-time algorithm [3] and Jin and Wu's deterministic O(t log t log log t) time algorithm, and later randomized O(t log t)-time algorithm from SOSA last improve the running time to O(t log t) by randomization. year [7]. All these improved algorithms use convolu- tions (i.e., FFT) or other algebraic techniques. There 1 Introduction are also conditional lower bounds [1] to suggest that get- ting better than t1−" running time might not be possible In the change-making (or coin changing) problem, a for subset sum (ignoring nO(1) factors). Of course, as a cashier wants to give exactly t amount of money to the function of n, improving upon 2n=2 worst-case time has customer, choosing from a set of coins, where each type remained a longstanding open problem. of coin has a positive integer value and has unlimited Despite all these recent works on subset sum, the supply, and the cashier wants to minimize the number change-making problem has not received as much at- of coins used. More formally, given a set V of n positive tention, and we are not aware of any reported im- integers (coin values) and a target number t, we want provements. One paper [10] provided conditional hard- to select the fewest number of elements from V that ness results for knapsack-related problems, including a sum to exactly t, where an element may be picked stronger version of the change-making problem with a more than once. This problem is a popular exercise in general linear objective function. Goebbels et al. [5] algorithm textbooks, where the standard solution runs noted an O(mt log t)-time algorithm for the decision in O(nt) time by dynamic programming [13]. (The naive problem of testing whether there is a solution with at greedy algorithm may fail to give optimal solutions for most m coins, which is better for small m, but their arbitrary sets of coin values.) The problem is known to solution uses convolution in a very naive way. The be weakly NP-hard [11]. situation is somewhat ironic, considering that change- The change-making problem is closely related to making seems not as difficult to solve via convolution, many other well known problems with similar O(nt)- because duplicates are allowed (in previous works on time textbook solutions, the most relevant of which solving subset sum via convolution [8, 3], much of the include challenge is about how to avoid duplicates). Indeed, an • subset sum: select elements from V to sum to O(t polylog t)-time solution follows almost immediately exactly t, but an element may be picked at most by combining convolution with repeated squaring|we once, and a minimum solution is not required; point out some of these easily rediscoverable solutions in Section 3.1 • unbounded knapsack: select elements from V to Following these straightforward solutions with extra sum to at most t, and an element may be picked logarithmic factors, we present a new simple determin- more than once, but we want to maximize a general istic algorithm in Section 4 that improves the running linear objective function. 1For example, the first solution in Section 3 has appeared ∗Department of Computer Science, University of Illinois at in an algorithms homework by Sariel Har-Peled; see the second Urbana-Champaign, USA, ftmc,[email protected]. Work page of https://courses.engr.illinois.edu/cs473/fa2018/hw/ supported in part by NSF Grant CCF-1814026. hw_03.pdf. Copyright c 2020 by SIAM Unauthorized reproduction of this article is prohibited time to O(t log t log log t), and a further refinement us- Lemma 2.3. We can compute the convolution A∗t B of ing (Las Vegas) randomization in Section 5 that achieves two arrays A and B in deterministic O(t log t) time, by O(t log t) expected running time. FFT. We feel that the succession of improved solutions presented here is well suitable for teaching, considering Boolean convolution. When the elements of A and B the popularity and natural appeal of the change-making are Boolean values in f0; 1g, we can define the Boolean problem. convolution of A and B (with respective size t1 and t2) to be an array A ◦ B with t1 + t2 − 1 elements such that Wt1−1 2 Preliminaries (A◦B)[i] = j=0 (A[j]^B[i−j]) for 0 ≤ i ≤ t1 +t2 −2 The change-making problem can be formally defined as (where we assume out-of-range values are 0). Similarly follows: let A ◦t B denote the array containing the first t + 1 elements of A ◦ B. It is easy to see (A ◦ B)[i] = 1 iff Problem 2.1. (Change Making (Optimization (A ∗ B)[i] > 0, so we can compute A ◦t B by Lemma 2.3 Version)) Given a set V = fv1; : : : ; vng of n nonneg- in deterministic O(t log t) time. ative integers (coin values) and an integer t, find the The following lemma states that speedup is possible smallest multiset S (duplicates allowed) contained in V with randomization, if we can tolerate error with prob- such that S sums to exactly t, i.e., find the minimum m∗ ability p per entry. This improvement will be needed Pn Pn of i=1 mi subject to the constraint that i=1 mivi = t, only in our final randomized algorithm in Section 5. where mi 2 N. Lemma 2.4. Given two arrays A and B with size O(t) For simplicity of presentation, we focus on finding and 0 < p < 1, we can compute an array C in ∗ 1 the minimum number of coins m . It is possible to randomized O(t log p ) time such that for all 0 ≤ i ≤ t: modify our algorithms to return the optimal multiset of coins without increasing the asymptotic running time; • If (A ◦t B)[i] = 0, then C[i] = 0. see the remark at the end of Section 4. • If (A ◦ B)[i] = 1, then Pr[C[i] = 1] ≥ 1 − p. Without loss of generality, we assume that 0 is in V , t since adding a coin value 0 does not affect the optimal Proof. For p = 1=2, this was noted for example by solution. This assumption ensures monotonicity, which Indyk [6]. Roughly, we use Freivald's technique [4] to will be useful: if there is a solution using m coins, then 0 0 reduce Boolean convolution to convolution over GF(2), there is a solution using m coins for any m ≥ m. We with constant error probability. The latter problem can may assume that n ≤ t. Trivially, m∗ ≤ t (unless ∗ be solved by packing k = Θ(log t) bits and compute m = 1). t k convolution of arrays with size O( k ) over GF(2 ) by Some of our algorithms will solve the decision FFT. version of the problem as a stepping stone: We can further reduce the error probability to any p < 1 by repeating O(log 1 ) times independently and Problem 2.2. (Change Making (Decision Ver- p taking the entry-wise or of the results. sion)) Given a set V = fv1; : : : ; vng of n nonnegative integers (coin values), an integer t, and an integer m, decide whether m∗ ≤ m, i.e., whether there is a multiset 3 Basic Algorithms S with m coins (counting duplicates) such that S sums We first present two basic algorithms for the change- to exactly t, i.e., whether there exist mi 2 N such that making problem. Pn Pn i=1 mivi = t and i=1 mi = m. First solution. The first solution solves the decision We use the standard word-RAM model with word version of the problem in O(t log2 t) time, and the length w = Θ(log t) in this paper. optimization version in O(t log3 t) time. For any k, let Ck[0; : : : ; t] denote the Boolean array where Ck[j] = 1 iff Convolution. Let A[0; : : : ; t1 − 1] be an array with we can sum to exactly j using k coins. Given a value m, ∗ t1 elements, and let B[0; : : : ; t2 − 1] be an array with we can decide whether m ≥ m by computing Cm[t]. It t2 elements. The convolution of A and B is an array is easy to compute C1 in O(t) time, and we can compute A ∗ B with t1 + t2 − 1 elements such that (A ∗ B)[i] = Cm recursively (by repeated squaring with respect to t −1 P 1 the operator ◦ ): if m is even, C = C m ◦ C m , j=0 A[j]B[i − j] for 0 ≤ i ≤ t1 + t2 − 2 (where we t m 2 t 2 assume out-of-range values are 0).
Recommended publications
  • Trees of Irreducible Numerical Semigroups
    Rose-Hulman Undergraduate Mathematics Journal Volume 14 Issue 1 Article 5 Trees of Irreducible Numerical Semigroups Taryn M. Laird Northern Arizona University, [email protected] Jose E. Martinez Northern Arizona University Follow this and additional works at: https://scholar.rose-hulman.edu/rhumj Recommended Citation Laird, Taryn M. and Martinez, Jose E. (2013) "Trees of Irreducible Numerical Semigroups," Rose-Hulman Undergraduate Mathematics Journal: Vol. 14 : Iss. 1 , Article 5. Available at: https://scholar.rose-hulman.edu/rhumj/vol14/iss1/5 Rose- Hulman Undergraduate Mathematics Journal Trees of Irreducible Numerical Semigroups Taryn M. Laird and Jos´eE. Martinez a Volume 14, No. 1, Spring 2013 Sponsored by Rose-Hulman Institute of Technology Department of Mathematics Terre Haute, IN 47803 Email: [email protected] a http://www.rose-hulman.edu/mathjournal Northern Arizona University Rose-Hulman Undergraduate Mathematics Journal Volume 14, No. 1, Spring 2013 Trees of Irreducible Numerical Semigroups Taryn M. Laird and Jos´eE. Martinez Abstract.A 2011 paper by Blanco and Rosales describes an algorithm for construct- ing a directed tree graph of irreducible numerical semigroups of fixed Frobenius numbers. This paper will provide an overview of irreducible numerical semigroups and the directed tree graphs. We will also present new findings and conjectures concerning the structure of these trees. Acknowledgements: We would like to give a special thanks to our mentor, Jeff Rushall, for his help and guidance, and to Ian Douglas for sharing his expertise in programming. Page 58 RHIT Undergrad. Math. J., Vol. 14, No. 1 1 Introduction There are many problems in which we unknowingly encounter numerical semigroups in mathematics.
    [Show full text]
  • Factoring in the Chicken Mcnugget Monoid
    Mathematics Magazine ISSN: 0025-570X (Print) 1930-0980 (Online) Journal homepage: http://maa.tandfonline.com/loi/umma20 Factoring in the Chicken McNugget Monoid Scott T. Chapman & Chris O’Neill To cite this article: Scott T. Chapman & Chris O’Neill (2018) Factoring in the Chicken McNugget Monoid, Mathematics Magazine, 91:5, 323-336, DOI: 10.1080/0025570X.2018.1515559 To link to this article: https://doi.org/10.1080/0025570X.2018.1515559 Published online: 07 Dec 2018. Submit your article to this journal Article views: 128 View Crossmark data Full Terms & Conditions of access and use can be found at http://maa.tandfonline.com/action/journalInformation?journalCode=umma20 ARTICLES Factoring in the Chicken McNugget Monoid SCOTT T. CHAPMAN Sam Houston State University Huntsville, TX 77341-2206 [email protected] CHRIS O’NEILL University of California Davis Davis, CA 95616 [email protected] People just want more of it.—Ray Kroc [9] Every day, 34 million Chicken McNuggets are sold worldwide [4]. At most McDonalds locations in the United States today, Chicken McNuggets are sold in packs of 4, 6, 10, 20, 40, and 50 pieces. However, shortly after their introduction in 1979, they were sold in packs of 6, 9, and 20. The following problem spawned from the use of these latter three numbers. The Chicken McNugget Problem. What numbers of Chicken McNuggets can be ordered using only packs with 6, 9, or 20 pieces? Early references to this problem can be found in [28] and [32]. Positive integers satisfying the Chicken McNugget Problem are now known as McNugget numbers [23].
    [Show full text]
  • The Frobenius Problem in a Free Monoid
    The Frobenius Problem in a Free Monoid by Zhi Xu A thesis presented to the University of Waterloo in ful¯llment of the thesis requirement for the degree of Doctor of Philosophy in Computer Science Waterloo, Ontario, Canada, 2009 °c Zhi Xu 2009 I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required ¯nal revisions, as accepted by my examiners. I understand that my thesis may be made electronically available to the public. ii Abstract Given positive integers c1; c2; : : : ; ck with gcd(c1; c2; : : : ; ck) = 1, the Frobenius prob- lem (FP) is to compute the largest integer g(c1; c2; : : : ; ck) that cannot be written as a non-negative integer linear combination of c1; c2; : : : ; ck. The Frobenius prob- lem in a free monoid (FPFM) is a non-commutative generalization of the Frobe- nius problem. Given words x1; x2; : : : ; xk such that there are only ¯nitely many words that cannot be written as concatenations of words in f x1; x2; : : : ; xk g, the FPFM is to ¯nd the longest such words. Unlike the FP, where the upper bound 2 g(c1; c2; : : : ; ck) · max1·i·k ci is quadratic, the upper bound on the length of the longest words in the FPFM can be exponential in certain measures and some of the exponential upper bounds are tight. For the 2FPFM, where the given words over § are of only two distinct lengths m and n with 1 < m < n, the length of the longest omitted words is · g(m; m j§jn¡m + n ¡ m).
    [Show full text]
  • Download The
    Visit : https://hemanthrajhemu.github.io Join Telegram to get Instant Updates: https://bit.ly/VTU_TELEGRAM Contact: MAIL: [email protected] INSTAGRAM: www.instagram.com/hemanthraj_hemu/ INSTAGRAM: www.instagram.com/futurevisionbie/ WHATSAPP SHARE: https://bit.ly/FVBIESHARE Introduction to The Design & ~ ~ Analysis of Algorithms IND EDITION " ~ Anany Levitin Villanova University Boston San Francisco New York London Toronto Sydney Tokyo Singapore Madrid Mexico City Munich Paris Cape Town Hong Kong Montreal https://hemanthrajhemu.github.io Contents ix 2.6 Empirical Analysis of Algorithms 84 Exercises 2.6 90 2.7 Algorithm Visualization 91 Summary 95 3 Brute Force 97 3.1 Selection Sort and Bubble Sort 98 Selection Sort 98 Bubble Sort 100 Exercises 3.1 102 3.2 Sequential Search and Brute-Force String Matching 103 Sequential Search 103 Brute-Force String Matching 104 Exercises 3.2 105 3.3 Closest-Pair and Convex-Hull Problems by Brute Force 107 Closest-Pair Problem 107 Convex-Hull Problem 108 Exercises 3.3 112 3.4 Exhaustive Search 114 Traveling Salesman Problem 114 Knapsack Problem 115 Assignment Problem 116 Exercises 3.4 119 Summary 120 4 Divide-and-Conquer 123 4.1 Mergesort 125 Exercises 4.1 128 4.2 Quicksort 129 Exercises 4.2 134 4.3 Binary Search 135 Exercises 4.3 138 https://hemanthrajhemu.github.io r 111 )( Contents I ' i::! 4.4 Binary Tree Traversals and Related Properties 139 Exercises 4.4 142 I:],, 4.5 Multiplication of Large Integers and Strassen's Matrix Multiplication 144 Multiplication of Large Integers 144 Strassen's Matrix
    [Show full text]
  • The Frobenius Problem in a Free Monoid
    The Frobenius Problem in a Free Monoid by Zhi Xu A thesis presented to the University of Waterloo in ful¯llment of the thesis requirement for the degree of Doctor of Philosophy in Computer Science Waterloo, Ontario, Canada, 2009 °c Zhi Xu 2009 I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required ¯nal revisions, as accepted by my examiners. I understand that my thesis may be made electronically available to the public. ii Abstract Given positive integers c1; c2; : : : ; ck with gcd(c1; c2; : : : ; ck) = 1, the Frobenius prob- lem (FP) is to compute the largest integer g(c1; c2; : : : ; ck) that cannot be written as a non-negative integer linear combination of c1; c2; : : : ; ck. The Frobenius prob- lem in a free monoid (FPFM) is a non-commutative generalization of the Frobe- nius problem. Given words x1; x2; : : : ; xk such that there are only ¯nitely many words that cannot be written as concatenations of words in f x1; x2; : : : ; xk g, the FPFM is to ¯nd the longest such words. Unlike the FP, where the upper bound 2 g(c1; c2; : : : ; ck) · max1·i·k ci is quadratic, the upper bound on the length of the longest words in the FPFM can be exponential in certain measures and some of the exponential upper bounds are tight. For the 2FPFM, where the given words over § are of only two distinct lengths m and n with 1 < m < n, the length of the longest omitted words is · g(m; m j§jn¡m + n ¡ m).
    [Show full text]