1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
garik1379 [7]
3 years ago
7

Consider the problem of making change for n cents using the fewest number of coins. Assume that each coins value is an integer.

a. You have available coin denominations of 1 cent, 5 cents, 10 cents, 25 cents, as in the US coins of penny, nickel, dime, quarter. Assume there is infinite availability of each of these four coin denomination types. Describe a greedy algorithm to make change using the fewest number of coins. b. Consider your greedy algorithm and making change for n=30 cents. Show that the optimal solution for making change includes your greedy choice. To do so, assume that your greedy choice is not in the optimal solution. Then use the "cut and paste" argument to show that you can replace other coins by your greedy choice, therefore finding a better solution than what was assumed to be optimal. This is in contradiction to the assumption, so your greedy choice is in the optimal solution. c. Although the greedy algorithm is optimal for the US coins, it is not necessarily optimal for any set of coins. Give an example of a different set of made up coin denominations with different values, for which the greedy algorithm does not yield an optimal solution. Your set should include a penny so that there is a solution for every value of n. As before, assume there is infinite availability of each of the coin denomination types. Show specifically a counter example in which the greedy algorithm yields a change solution that is not optimal, that is, does not include the fewest number of coins. d. Name another algorithmic approach that will find an optimal solution to your example in (c).
Computers and Technology
1 answer:
Oksana_A [137]3 years ago
5 0

Answer:

There are two algorithms in which apply different optimal solutions.

They are: A Dynamic and Naive recursive programs

Explanation:

// A Naive recursive C++ program to find minimum of coins  

// to make a given change V  

#include<bits/stdc++.h>  

using namespace std;  

// m is size of coins array (number of different coins)

int minCoins(int coins[], int m, int V)  

{  

// base case  

if (V == 0) return 0;  

// Initialize result

int res = INT_MAX;  

// Try every coin that has smaller value than V  

for (int i=0; i<m; i++)  

{  

if (coins[i] <= V)  

{  

 int sub_res = minCoins(coins, m, V-coins[i]);  

 // Check for INT_MAX to avoid overflow and see if  

 // result can minimized

 if (sub_res != INT_MAX && sub_res + 1 < res)  

  res = sub_res + 1;  

}  

}  

return res;  

}  

// Driver program to test above function  

int main()  

{  

int coins[] = {9, 6, 5, 1};  

int m = sizeof(coins)/sizeof(coins[0]);  

int V = 11;  

cout << "Minimum coins required is "

 << minCoins(coins, m, V);  

return 0;  

}  

.........................................

// A Dynamic Programming based C++ program to find minimum of coins  

// to make a given change V  

#include<bits/stdc++.h>  

using namespace std;  

// m is size of coins array (number of different coins)  

int minCoins(int coins[], int m, int V)  

{  

// table[i] will be storing the minimum number of coins  

// required for i value. So table[V] will have result  

int table[V+1];  

// Base case (If given value V is 0)  

table[0] = 0;  

// Initialize all table values as Infinite  

for (int i=1; i<=V; i++)  

 table[i] = INT_MAX;  

// Compute minimum coins required for all  

// values from 1 to V  

for (int i=1; i<=V; i++)  

{  

 // Go through all coins smaller than i  

 for (int j=0; j<m; j++)  

 if (coins[j] <= i)  

 {  

  int sub_res = table[i-coins[j]];  

  if (sub_res != INT_MAX && sub_res + 1 < table[i])  

   table[i] = sub_res + 1;  

 }  

}  

return table[V];  

}  

// Driver program to test above function  

int main()  

{  

int coins[] = {9, 6, 5, 1};  

int m = sizeof(coins)/sizeof(coins[0]);  

int V = 11;  

cout << "Minimum coins required is "

 << minCoins(coins, m, V);  

return 0;  

}  

You might be interested in
The CPU converts into information. The CPU is the mastermind of the computer, controlling everything that goes on through a seri
Harman [31]

Answer:

Mathematical sequences

Explanation:

Just did it

5 0
3 years ago
Read 2 more answers
6 The part of the computer that contains the brain or central processing unit is also known as the ?
Olin [163]
Answer:  "CPU" .
________________________________
4 0
3 years ago
Good participation in music is strictly limited to those who perform well. true or false
sdas [7]
The answer would be false because you don't have to be good at it to participate and try your hardest
8 0
3 years ago
Read 2 more answers
What are the side effects of overclocking?
Oksana_A [137]

Answer:

Reduced processor lifespan, reduced fan cooler performance over time, bugs.

Explanation:

The reason is that when you overclock your processor you are increasing its base speeds in GHZ. The processor was designed to work at a determined speed, let's say 3.00 ghz. If you increase this speed to 4.00 ghz, it's not just that now it's working faster, it also draws more power from your power supply, and increases the heat that the chip is taking. Processors are designed to endure high temperatures, therefore, you will likely not see any damaged in short term, but your components life span will be severely reduced, also depending on how much you overclock the processor, and the stability of your system, you can see bugs, unexpected restarts, and strange behavior of the computer. As an example, the i5 4670k runs at 3.80 stock speed, it can reach 50 / 65 degrees under full load. If you raise the speed up to 4.5ghz it will reach 70/80 degrees, depending on your ambient temperature and other factors.

6 0
3 years ago
Stages of reverse engineering
ivann1987 [24]

Answer:

Capture Data, Refine the Model, and then Manufacture it.

Explanation:

5 0
3 years ago
Other questions:
  • What features are provided by most GUIs?
    7·1 answer
  • Please answer <br><br> Steps 1-6 <br><br> Visual basics
    7·1 answer
  • Create a program that asks the user to enter grade scores. Use a loop to request each score and add it to a total. Continue acce
    9·1 answer
  • In our discussion of Computer Hardware, we talked about three essential hardware components that are there inside every computer
    14·1 answer
  • PLEASE HELP!
    14·2 answers
  • Very Short Answer Type Question (any 9)
    12·1 answer
  • What is the best wi-fi name you have ever seen?
    10·1 answer
  • Simple Java programming
    15·2 answers
  • Identify a characteristic that is a disadvantage of cloud-based hosting.
    11·1 answer
  • True or False? The background color block should be inserted after all the images are added.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!