The English system in use before 1971 (when decimal currency was introduced) was an example of a \natural" coin system for which the greedy algorithm

Similar documents
for average case complexity 1 randomized reductions, an attempt to derive these notions from (more or less) rst

Three-dimensional Stable Matching Problems. Cheng Ng and Daniel S. Hirschberg. Department of Information and Computer Science

ON THE COMPLEXITY OF SOLVING THE GENERALIZED SET PACKING PROBLEM APPROXIMATELY. Nimrod Megiddoy

Linear Algebra (part 1) : Vector Spaces (by Evan Dummit, 2017, v. 1.07) 1.1 The Formal Denition of a Vector Space

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Preface These notes were prepared on the occasion of giving a guest lecture in David Harel's class on Advanced Topics in Computability. David's reques

Lower Bounds for Shellsort. April 20, Abstract. We show lower bounds on the worst-case complexity of Shellsort.

Introduction and mathematical preliminaries

Essentials of Intermediate Algebra

Lexicographic Flow. Dexter Kozen Department of Computer Science Cornell University Ithaca, New York , USA. June 25, 2009

Complexity analysis of job-shop scheduling with deteriorating jobs

Contents. 1 Introduction to Dynamics. 1.1 Examples of Dynamical Systems

Lecture 9: Cardinality. a n. 2 n 1 2 n. n=1. 0 x< 2 n : x = :a 1 a 2 a 3 a 4 :::: s n = s n n+1 x. 0; if 0 x<

NP-Completeness. f(n) \ n n sec sec sec. n sec 24.3 sec 5.2 mins. 2 n sec 17.9 mins 35.

On-line Bin-Stretching. Yossi Azar y Oded Regev z. Abstract. We are given a sequence of items that can be packed into m unit size bins.

On the classication of algebras

Theory of Computation Chapter 1: Introduction

IBM Almaden Research Center, 650 Harry Road, School of Mathematical Sciences, Tel Aviv University, TelAviv, Israel

g(.) 1/ N 1/ N Decision Decision Device u u u u CP

LECTURE NOTES IN CRYPTOGRAPHY

Theorem 1 can be improved whenever b is not a prime power and a is a prime divisor of the base b. Theorem 2. Let b be a positive integer which is not

1 Matrices and Systems of Linear Equations

to t in the graph with capacities given by u e + i(e) for edges e is maximized. We further distinguish the problem MaxFlowImp according to the valid v

Functions and Their Graphs

Lecture 14 - P v.s. NP 1

satisfying ( i ; j ) = ij Here ij = if i = j and 0 otherwise The idea to use lattices is the following Suppose we are given a lattice L and a point ~x

Homework 1 Solutions ECEn 670, Fall 2013

CS264: Beyond Worst-Case Analysis Lecture #18: Smoothed Complexity and Pseudopolynomial-Time Algorithms

The Inclusion Exclusion Principle and Its More General Version

Lecture 9 : PPAD and the Complexity of Equilibrium Computation. 1 Complexity Class PPAD. 1.1 What does PPAD mean?

Upper and Lower Bounds for Tree-like. Cutting Planes Proofs. Abstract. In this paper we study the complexity of Cutting Planes (CP) refutations, and

Divisor matrices and magic sequences

CS264: Beyond Worst-Case Analysis Lecture #15: Smoothed Complexity and Pseudopolynomial-Time Algorithms

2 PAVEL PUDLAK AND JIRI SGALL may lead to a monotone model of computation, which makes it possible to use available lower bounds for monotone models o

Contents. 2.1 Vectors in R n. Linear Algebra (part 2) : Vector Spaces (by Evan Dummit, 2017, v. 2.50) 2 Vector Spaces

MARKOV CHAINS: STATIONARY DISTRIBUTIONS AND FUNCTIONS ON STATE SPACES. Contents

1 Ordinary points and singular points

Extracted from a working draft of Goldreich s FOUNDATIONS OF CRYPTOGRAPHY. See copyright notice.

P versus NP. Math 40210, Fall November 10, Math (Fall 2015) P versus NP November 10, / 9

The Complexity and Approximability of Finding. Maximum Feasible Subsystems of Linear Relations. Abstract

You must have: Ruler graduated in centimetres and millimetres, pair of compasses, pen, HB pencil, eraser.

Structural Grobner Basis. Bernd Sturmfels and Markus Wiegelmann TR May Department of Mathematics, UC Berkeley.

Upper and Lower Bounds on the Number of Faults. a System Can Withstand Without Repairs. Cambridge, MA 02139

1 Strict local optimality in unconstrained optimization

Abstract. This paper discusses polynomial-time reductions from Hamiltonian Circuit (HC),

Coins with arbitrary weights. Abstract. Given a set of m coins out of a collection of coins of k unknown distinct weights, we wish to

Vector Space Basics. 1 Abstract Vector Spaces. 1. (commutativity of vector addition) u + v = v + u. 2. (associativity of vector addition)

2 Exercises 1. The following represent graphs of functions from the real numbers R to R. Decide which are one-to-one, which are onto, which are neithe

17 Galois Fields Introduction Primitive Elements Roots of Polynomials... 8

Dexter Kozen 1 Susan Landau 2 Richard Zippel 1. Abstract. Functional decomposition whether a function f(x) can be

Eigenvalue problems and optimization

2.57 PART E: THE FUNDAMENTAL THEOREM OF ALGEBRA (FTA) The Fundamental Theorem of Algebra (FTA)

University of Missouri. In Partial Fulllment LINDSEY M. WOODLAND MAY 2015

A Polynomial Time Deterministic Algorithm for Identity Testing Read-Once Polynomials

Lattice Basis Reduction and the LLL Algorithm

3. pour from one decanter to the other until either the receiving decanter is full or the poured decanter is empty.

Analytic Number Theory Solutions

There are two things that are particularly nice about the first basis

10.4 The Kruskal Katona theorem

Analog Neural Nets with Gaussian or other Common. Noise Distributions cannot Recognize Arbitrary. Regular Languages.

2 COLORING. Given G, nd the minimum number of colors to color G. Given graph G and positive integer k, is X(G) k?

3. pour from one decanter to the other until either the receiving decanter is full or the poured decanter is empty.

NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty.

Basic Theorems about Independence, Spanning, Basis, and Dimension

Chapter Generating Functions

Classication of greedy subset-sum-distinct-sequences

Introduction to Complexity Theory

Contents. 4 Arithmetic and Unique Factorization in Integral Domains. 4.1 Euclidean Domains and Principal Ideal Domains

Math 101 Study Session Spring 2016 Test 4 Chapter 10, Chapter 11 Chapter 12 Section 1, and Chapter 12 Section 2

3. G. Groups, as men, will be known by their actions. - Guillermo Moreno

The Best Circulant Preconditioners for Hermitian Toeplitz Systems II: The Multiple-Zero Case Raymond H. Chan Michael K. Ng y Andy M. Yip z Abstract In

SOLUTION TO RUBEL S QUESTION ABOUT DIFFERENTIALLY ALGEBRAIC DEPENDENCE ON INITIAL VALUES GUY KATRIEL PREPRINT NO /4

8. Prime Factorization and Primary Decompositions

MATH 2400 LECTURE NOTES: POLYNOMIAL AND RATIONAL FUNCTIONS. Contents 1. Polynomial Functions 1 2. Rational Functions 6

The limitedness problem on distance automata: Hashiguchi s method revisited

Multicommodity Flows and Column Generation

Calculus and linear algebra for biomedical engineering Week 3: Matrices, linear systems of equations, and the Gauss algorithm

Abstract algebra is the study of structures that certain collections of. 204, linear algebra, or in CS 221, discrete structures.

Linear Algebra (part 1) : Matrices and Systems of Linear Equations (by Evan Dummit, 2016, v. 2.02)

THREE GENERALIZATIONS OF WEYL'S DENOMINATOR FORMULA. Todd Simpson Tred Avon Circle, Easton, MD 21601, USA.

Definition For a set F, a polynomial over F with variable x is of the form

LESSON 6.1 EXPONENTS LESSON 6.1 EXPONENTS 253

8.5 Taylor Polynomials and Taylor Series

Discrete Applied Mathematics. Tighter bounds of the First Fit algorithm for the bin-packing problem

Single processor scheduling with time restrictions

A version of for which ZFC can not predict a single bit Robert M. Solovay May 16, Introduction In [2], Chaitin introd

A TOUR OF LINEAR ALGEBRA FOR JDEP 384H

We are going to discuss what it means for a sequence to converge in three stages: First, we define what it means for a sequence to converge to zero

Circuit depth relative to a random oracle. Peter Bro Miltersen. Aarhus University, Computer Science Department

3. pour from one decanter to the other until either the receiving decanter is full or the poured decanter is empty.

1182 L. B. Beasley, S. Z. Song, ands. G. Lee matrix all of whose entries are 1 and =fe ij j1 i m 1 j ng denote the set of cells. The zero-term rank [5

Math 302 Module 4. Department of Mathematics College of the Redwoods. June 17, 2011

Notes on Systems of Linear Congruences

Test 2. Monday, November 12, 2018

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

About the relationship between formal logic and complexity classes

Spurious Chaotic Solutions of Dierential. Equations. Sigitas Keras. September Department of Applied Mathematics and Theoretical Physics

K-center Hardness and Max-Coverage (Greedy)

An Algorithm to Calculate the Kernel of Certain Polynomial Ring Homomorphisms

CSE 417. Chapter 4: Greedy Algorithms. Many Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Transcription:

A Polynomial-time Algorithm for the Change-Making Problem David Pearson Computer Science Department Cornell University Ithaca, New York 14853, USA pearson@cs.cornell.edu June 14, 1994 Abstract The change-making problem is the problem of representing a given value with the fewest coins possible from a given set of coin denominations. To solve this problem for arbitrary coin systems is NP-hard [L]. We investigate the problem of determining whether the greedy algorithm always produces the optimal result for a given coin system. Chang and Gill [CG] show that this can be solved in time polynomial in the size of the largest coin and in the number of coins. Kozen and Zaks [KZ] give a more ecient algorithm, and pose as an open problem whether there is an algorithm to solve this problem which is polynomial in the size of the input. In this paper, we will derive such an algorithm. We rst obtain a characterization of the smallest counterexample (if there is one) for which the greedy algorithm is not optimal. We then derive a set of O(n 2 ) possible values (where n is the number of coins) which must contain the smallest counterexample. Each can be tested with O(n) arithmetic operations, giving us an O(n 3 ) algorithm. 1 Introduction In the change-making problem, we are given a nite set of coin denominations and an unlimited supply of coins in each denomination. We want to represent a given value with the fewest coins possible. The problem of determining the optimal representation in general is NP-hard [GJ, KZ]. However, in almost all coin systems in use in the world, the problem can be eciently solved by the greedy algorithm. This algorithm repeatedly takes the largest coin whose value is no larger than the remaining amount. For general systems, the greedy algorithm is not always optimal. With the coin system 1,3,4, for example, the value 6 will be represented by the greedy algorithm as 4+1+1, but the optimal representation, 3+3, uses one coin fewer. 1

The English system in use before 1971 (when decimal currency was introduced) was an example of a \natural" coin system for which the greedy algorithm was not optimal. The coin denominations were (in units of a penny) 1, 1, 3, 6, 12 (shilling), 24 (orin), 30 (halfcrown), 60 (crown), and 240 (pound). 48 pence would be represented as 30+12+6 by the 2 greedy algorithm, while the minimal representation is 24+24 (two orins). The picture was further complicated by an obsolete coin, the Guinea, with a value of 21 shillings. In this paper, we will investigate the problem of determining, for a given coin system, whether the greedy algorithm always yields the optimal representation. Denition 1 A coin system is a nite set of positive integers, c 1 > c 2 > > c n. We will assume that the smallest coin, c n, has value 1, since otherwise not all values would be representable. Let C be the n-vector (c 1 ; c 2 ; : : : ; c n?1 ; c n ). A representation in C of a nonnegative integer x is an n-vector V of non-negative integers such that V C = x, where V C denotes the inner product of V with C, P n i=1 v i c i. The size jv j of a representation V is the number of coins in it, i.e. V (1; 1; : : : ; 1). Note that we write the n-vectors with the higher coin denominations rst. The leading terms of the representation vectors are then the most signicant terms, as they are in positional number systems, or car odometers. The greedy algorithm has a particularly simple relationship with the lexicographic ordering on the representation vectors. Denition 2 For n-vectors U = (u 1 ; u 2 ; : : : ; u n ) and V = (v 1 ; v 2 ; : : : ; v n ), write U < V if U lexicographically precedes V, i.e. if for some i: 1 i n, u i < v i and for all j: 1 j < i, u j = v j. The greedy representation of x, denoted by G(x), is the lexicographically greatest of all the representations of x. Notice that if x < y, then U = G(x)+(0; 0; : : : ; 0; y? x) is a representation for y. Clearly G(x) < U. By the denition of G(y), we know that U G(y), so G(x) < G(y). The greedy representation, in other words, has the nice property of preserving order. For a given value x, there may be several representations with the same size, including the minimum size. We would like to choose a unique representative of all the minimum-size representations. Denition 3 The minimal representation of x, denoted by M(x), is the lexicographically greatest of all the representations of x of minimum size. We call the coin system C canonical if G(x) = M(x) for all x. It is not immediately clear whether there is a nite process to show that a coin system is canonical, since there are innitely many values x to test. However, Chang and Gill [CG] show that if no counterexample exists for which G(x) 6= M(x) in a certain nite set, then no counterexample exists. The size of this set is polynomial in the value of the largest coin c 1, in the worst case O(c 13 ). Kozen and Zaks [KZ] show that the smallest counterexample w (if there is one) must lie in the range c n?2 w < c 1 + c 2. This gives a set of candidates whose size is linear in c 1, and they give an O(nc 1 ) algorithm for testing whether the system is canonical. This time bound is still potentially exponential in the size of the input, however. 2

They give another algorithm which takes time polynomial in log(c 1 ) for any xed number of coins, but exponential in the number of coins. They leave it as an open problem whether an algorithm exists which is polynomial in the size of the input. It is NP-hard to decide, for an arbitrary coin system, whether the greedy algorithm is optimal for a specic value x [KZ]. Answering the same question for all x seems intuitively harder, but is actually easier. The smallest counterexample is much easier to test than an arbitrary one, and it has a particular structure which will make it easy to nd. In this paper, we obtain a set of possible counterexamples which is polynomial in the number of coins in the system and independent of the sizes of the coins. This will lead to a true polynomial-time algorithm. 2 A Polynomial-time algorithm In this section, we will characterize the smallest counterexample, if there is one, and derive a small (O(n 2 )) set of candidates that must include the smallest. As a preliminary, we rst need to establish some facts about minimal and greedy representations. For two vectors U and V, we will say that U V if each element u i of U is less than or equal to the corresponding element v i of V. Equivalently, V = U + D for some vector D of non-negative integers. If V is a representation of x, then U is a representation of the number x? D C x. It is a surprising fact that if V is a greedy or minimal representation, then U is also. Lemma 1 Call U greedy if U = G(U C), and minimal if U = M(U C). Then (a) if U V and V is greedy, then U is greedy (b) if U V and V is minimal, then U is minimal Proof. For (a), note that vector addition preserves lexicographic order: A B () A + D B + D Let U 0 be any representation of U C. Then U 0 C = U C (V? U + U 0 ) C = V C by linearity V? U + U 0 V since V greedy (and V? U non-negative) U 0 U since addition is order-preserving Thus U is greedy, since it is the lexicographically greatest representation of U C. For (b), dene A v B if jaj > jbj or (jaj = jbj and A B). Then the minimal representation is the greatest under v. Addition is again order-preserving with respect to v. The above proof is valid if we substitute v for. 2 3

Now suppose that C is not canonical. Let w be the smallest counterexample, i.e. the smallest element such that G(w) 6= M(w). We will characterize w, and show that it must be one of O(n 2 ) candidates. The fact that w is the smallest counterexample makes it easy to compute M(w), giving us a polynomial-time test. One important fact about w is that the sets of nonzero entries in G(w) and M(w) are disjoint. If this were not true, if both were nonzero in position k, for example, then we could subtract 1 from the kth position in both G(w) and M(w) to get two new vectors, which would be the greedy and minimal representations of w? c k, by Lemma 1, contradicting the minimality of w. Let M(w) = (m 1 ; m 2 ; : : : ; m n ), and let i and j denote the rst and last nonzero entries in M(w) respectively, i.e. m i 6= 0 and m j 6= 0, and m k = 0 for 1 k < i and j < k n. Note that M(w) < G(w) by the denition of G, but since they do not share any nonzero entries, G(w) must have a zero in position i and be nonzero in some earlier position. This means in particular that i > 1. We can now characterize M(w) in a precise way. The following theorem shows a close similarity between M(w) and G(c i?1? 1). Theorem 1 M(w) agrees with G(c i?1? 1) in entries 1 through j? 1, and is one greater in entry j. The remaining entries m j+1 ; : : : ; m n are all zero. Proof. Recall that G(w) must have a zero in position i and a nonzero entry in some earlier position. This means that w c i?1. On the other hand, subtracting one from the jth entry in M(w) results in a valid minimal representation for w? c j (by Lemma 1) which must also be the greedy representation, since there are no smaller counterexamples. This representation has no coin larger than c i, so w?c j < c i?1. Thus we get the following bounds: w? c j < c i?1 w (1) Let V = (v 1 ; v 2 ; : : : ; v n ) = G(c i?1? 1). Since c i?1? 1 c i, v i 6= 0. This means we can reduce both v i and m i by one to get new valid greedy representations G(c i?1? 1? c i ) and G(w? c i ). We know from (1) that c i?1? 1? c i < w? c i, so G(c i?1? 1? c i ) < G(w? c i ). Adding back the one in position i won't change their lexicographic ordering, so V < M(w) (2) On the other hand, if we decrease m j by one, we will get a valid greedy representation G(w? c j ). Since w? c j c i?1? 1 by (1), we have G(w? c j ) V. Combining this with (2), G(w? c j ) V < M(w). Notice that G(w? c j ) and M(w) dier only in entry j, so if V diered from them in any position before j, it could not lie between them. V and M(w) therefore agree in positions 1; 2; : : : ; j? 1, but V < M(w), so we must have v k < m k for some k j. But since m j+1 ; m j+2 ; : : : ; m n are all zero, this could only be true for entry j: v j < m j. But G(w? c j ) V, so m j? 1 v j. The only possible value for m j is thus v j + 1. 2 In a xed coin system, if we know i and j, Theorem 1 allows us to determine w exactly. There are only O(n 2 ) possible values of i and j to test, so we have obtained our polynomialsized sample set. 4

Notice that Theorem 1 gives us both the candidate w and the corresponding M(w) (which need be valid only if w is actually the smallest counterexample). To test each candidate in the set requires generating this potential M(w) and the true G(w), then checking whether jm(w)j < jg(w)j. This test can be performed in O(n) time, giving us an O(n 3 ) algorithm overall. 3 Acknowledgements I am very indebted to Dexter Kozen for posing this problem, and for sharing some of the clarity of his mathematical thought. The support of a Fannie and John Hertz Foundation Graduate Fellowship, and the National Science Foundation under grant CCR-9317320, is gratefully acknowledged. References [CG] Chang, S. K., A. Gill, \Algorithmic solution of the change-making problem," J. Assoc. Comput. Mach. 17:1 (January 1970), pp. 113-122. [GJ] Garey, M. R., D. S. Johnson, Computers and Intractability: a Guide to the Theory of NP-Completeness. W. H. Freeman, 1979. [KZ] Kozen, D., S. Zaks, \Optimal bounds for the change-making problem," Theor. Comput. Sci. 123 (1994), pp. 377-388. [L] Lueker, G. S., \Two NP-complete problems in nonnegative integer programming," Report No. 178, Computer Science Laboratory, Princeton University, 1975. 5