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
To change the print orientation from portrait to landscape, tap or click the ____ button on the print preview tab.
lianna [129]
<span>In certain instances, it makes sense to print documents in landscape orientation. Some examples include spreadsheets and tables, where the content within the document is wider than it is longer. If you print in portrait mode, it would cut off parts of the table or spreadsheet. In this case, you'll want to change the print settings to landscape. To change it to landscape, simply click the "landscape" button on the print preview tab.</span>
4 0
3 years ago
By default, what appears on your screen whenever a new email arrives?.
Troyanec [42]

By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

<h3>What is a Desktop Alert?</h3>

This is known to be a kind of  a notification that often shows on your desktop when a person is said to receive a new email message, a meeting request, or others.

Note that the Desktop Alerts need to be turned on by default and as such, By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

Learn more about Desktop from

brainly.com/question/7221406

#SPJ1

7 0
2 years ago
Traffic shaping reduces traffic by ________. preventing certain undesirable traffic from entering the network limiting the amoun
Lera25 [3.4K]

Answer:

Explanation:

Traffic Shaping is a technique for managing congestion on a network by delaying the flow of less important/desired packets on the network so more valuable/desirables ones are able to pass. Traffic shaping reduces traffic by preventing certain undesirable traffic from entering the network as well as limiting the amount of certain undesirable traffic entering the network.

5 0
3 years ago
For a line segment, show that clipping against the top of the clipping rectangle can be done independently of the clipping again
butalik [34]

Answer:

Explanation:

Solution is in the attached document.

3 0
3 years ago
Which two cisco products are equipped with the integrated connector to the cisco cws service? (choose two. )
jeka94

The cisco products that are equipped with the integrated connector to the cisco cws service include Cisco ESA and Cisco WSA.

<h3>What is an integrated connector?</h3>

It should be noted that an integrated connector are the components that are offered to connect with applications and data sources.

In this case, the cisco products that are equipped with the integrated connector to the cisco cws service include Cisco ESA and Cisco WSA.

Learn more about integrated connection on:

brainly.com/question/24196479

#SPJ12

8 0
2 years ago
Other questions:
  • An outdoor products company wants to test a new website design where customers can get information about their favorite outdoor
    6·1 answer
  • What is the accounting equation?
    12·1 answer
  • For most applications, saving sound files at the _____ bit resolution provides a good balance of sound quality and file size.
    15·2 answers
  • The operation of early electronic computing devices required:
    8·1 answer
  • Define a void function that calculates the sum (+), difference (-), product (*), quotient (/), and modulus (%) of two integer nu
    14·1 answer
  • How do I make sure I have full access to this app where do I put in payment information
    8·1 answer
  • Ben Dover is the name of my best immature joke thank you
    7·2 answers
  • Paul listed the websites he searched to find information on a career in biology ​
    15·1 answer
  • The data model shows the_______structrue of database.​
    14·1 answer
  • The recipient list cannot be edited.<br> Group of answer choices<br><br> True<br><br> False
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!