Algorithmic Paradigms

An algorithm paradigm is a generic model or framework which underlies the design of a class of algorithm. We have already covered some of them, those being:

We will distinguish the three distinct approach by solving the following problem:

Find the minimum number of coins needed to make change.

To provide a bit of context, suppose we have the following currency denomination:

Figure 5.1 Currency denominations.

Figure 5.1 Currency denominations.

And we have to pay the customer $x$ cents, our goal is now to devise a method to pay that amount to the customer while using the fewest number of coins — emphasizing on the “fewest”.

Greedy Way

The greedy approach is the simplest, conceptually. At each iteration, it selects the coin of the largest value, which is not greater than the remaining amount to be paid.

**GreedyChange(*money*)**
*Change* ← empty collection of coins 
while *money* > 0:
	*coin* ← largest denomination that does not exceed *money*
	add *coin* to *Change*
	*money* ← *money* - *coin*
return *Change*

Consider this scenario:

The algorithm will output Change[] = {25,10,5}, meaning the customer receives $25$ cents, $10$ cents, and $5$ cents. But, is this the optimal solution? Yes.

Figure 5.2a Greedy solution.

Figure 5.2a Greedy solution.