


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Change Amount: 63 Coin types: [1, 5, 10, 25] Run-time: 70.689 seconds Fewest number of coins 6 Number of Backtracking Nodes: 67,716,
Change Amount: 63 Coin types: [1, 5, 10, 25] Run-time: 45.815 seconds Fewest number of coins 6 Number of Backtracking Nodes: 67,716,
def recMC(change, coinValueList): global backtrackingNodes backtrackingNodes += 1 minCoins = change if change in coinValueList: return 1 else: for i in [c for c in coinValueList if c <= change]: numCoins = 1 + recMC(change - i, coinValueList) if numCoins < minCoins: minCoins = numCoins return minCoins
def recMC(change, coinValueList): global backtrackingNodes backtrackingNodes += 1 minCoins = change if change in coinValueList: return 1 else: for i in coinValueList: if i <= change: numCoins = 1 + recMC(change - i, coinValueList) if numCoins < minCoins: minCoins = numCoins return minCoins
Change Amount: 63 Coin types: [1, 5, 10, 25] Run-time: 0.036 seconds Fewest number of coins 6 The number of each type of coins is: number of 1-cent coins is 3 number of 5-cent coins is 0 number of 10-cent coins is 1 number of 25-cent coins is 2 Number of Backtracking Nodes: 4831
Change Amount: 63 Coin types: [25, 10, 5, 1] Run-time: 0.003 seconds Fewest number of coins 6 The number of each type of coins is: number of 25-cent coins is 2 number of 10-cent coins is 1 number of 5-cent coins is 0 number of 1-cent coins is 3 Number of Backtracking Nodes: 310