In this problem you are to write an empirical analysis program to determine statistically how good the greedy algorithm is with respect to the optimal DP algorithm for coin changing. To simplify our problem assume that you select randomly 5 coins who have a denomination from 1 to 100 with one of the coins being 1 cent. Make the number of coin denominations be a variable n so you can change it later. IE don't hard code 5.

For each selection you run the greedy algorithm and the DP algorithm on this problem to determine the number of coins to obtain T ( the total amount you are creating change for). If the greedy algorithm give k coins and the DP algorithm give m coins then we can calculate the percentage ( m/k * 100). For example , if m =2 and k=6 then the DP approach results in an answer that is 33.3 % of the greedy approach. The smaller the percentage then the better DP performs over greedy.

Here is pseudo code for the problem that you should implement.

n=5
AvePer = 0
for T = 100 to 500
for i=0 to 100
select n random coins which include a 1
m = CoinCtDP(T)
k = CoinCtGreedy(T)
AvePer += (m/k)
totalAve+= avePer/100;
printout totalAve/400
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.