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

Example-Counting Change

 

Consider the problem a cashier solves every time he counts out some amount of currency. The cashier has at his 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_inline67404, and let tex2html_wrap_inline63669 be the denomination of tex2html_wrap_inline57649. For example, if tex2html_wrap_inline57649 is a dime, then tex2html_wrap_inline67412. To count out a given sum of money A we find the smallest subset of P, say tex2html_wrap_inline67418, such that tex2html_wrap_inline67420.

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

displaymath67396

Given tex2html_wrap_inline67428 our objective is to minimize

displaymath67397

subject to the constraint

displaymath67398




next up previous contents index

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