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
A(n) __________ is a sequence of primitive data elements stored in sequential storage locations.
lys-0071 [83]

An array is a sequence of primitive data elements stored in sequential storage locations

4 0
2 years ago
An ARP broadcast is sent to the special MAC address ________.
mixas84 [53]
I do not understand what you mean
5 0
4 years ago
Read 2 more answers
Which of these are characteristics of compiler software? Check all of the boxes that apply. Compiler software compiles code. Com
Feliz [49]

Answer:compiler software translatesthe code into machine language

Explanation:

6 0
4 years ago
Read 2 more answers
Sperling's delayed partial report procedure provided evidence that
PSYCHO15rus [73]

Answer:

Option B is the correct answer to the following question.

Explanation:

The partial report is the procedure that provide the demonstration that is used in the Sperling's experiment. It is the technique in which the information stored in the secondary memory then dim within a seconds and it is the procedure in which the demonstration of the delayed partial report is provided. So, That's why the following option is correct.

7 0
3 years ago
You use the Save As dialog box to save a document in Web Page format.
iren [92.7K]
If this is a true or false: true.
4 0
3 years ago
Other questions:
  • You knew that you had to take this quiz so you logged into Blackboard and went to the quizzes section. In this scenario your com
    11·1 answer
  • What are the design concepts and assumptions behind a class, an object and the relationship between them? What are the roles met
    9·1 answer
  • When doing black and white photography, which file format should you use if possible? JPEG TIFF PNG RAW
    11·2 answers
  • ____ is designed for short-distance connections and has only a few lambdas, with a greater space between lambdas. Group of answe
    9·2 answers
  • NAND is logically complete. Use only NAND gates to constructgate-level circuits that compute the
    7·1 answer
  • There are 3 parts to an osha inspection. What are they
    9·1 answer
  • How dose computers it use the information to solve problems
    6·1 answer
  • Online banking is a convenience that mostly affects which area of your life?
    15·1 answer
  • QUESTION 9
    6·1 answer
  • Communication between a computer and a keyboard involves ______________ transmission.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!