Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Example-Counting Change

 

Consider the problem a cashier solves every time she counts out some amount of currency. The cashier has at her disposal a collection of notes and coins of various denominations and is required to count out a specified sum using the smallest possible number of pieces.

The problem can be expressed mathematically as follows: Let there be n pieces of money (notes or coins), tex2html_wrap_inline67121, and let tex2html_wrap_inline63402 be the denomination of tex2html_wrap_inline57368. For example, if tex2html_wrap_inline57368 is a dime, then tex2html_wrap_inline67129. To count out a given sum of money A we find the smallest subset of P, say tex2html_wrap_inline67135, such that tex2html_wrap_inline67137.

One way to represent the subset S is to use n variables tex2html_wrap_inline67143, such that

displaymath67113

Given tex2html_wrap_inline67145 our objective is to minimize

displaymath67114

subject to the constraint

displaymath67115




next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.