Let OPT(n) be the minimum number of coins required to get value n using the coins d1,d2,...,dk. Then we can think of dynamic programming recurrence equation to be
OPT(n)= min (1+OPT(n-di) for all i from 1 to k
This means that if I use one coin of value di for getting value n, then remaining coins size require to add value n-di should be minimum.
This we will create dynamic programming table name OPT whose value will grow linearly from 1 to N and it will check the minimum number of coins needed to compute OPT(n) using past value.
Base case:- OPT(di) = 1 for all i in range 1 to k
OPT(n) = INFINITE for n< d1 because there is no way to get value less than d1
Below is the algorithm which run in time O(Nk) in which OPT(N) will be minimum numbers of coin needed to have value N using the coins of value d1,d2,...,dk
![Minimum_Coins(N) 1. for i =1 to N:- 2 3. for i1 to k:- 4 5. for id1+1 to N: we already have estimate for value d1 OPT[1] = INFINITE \\initialization step OPT[di]1 only 1 coin is best solution for j=1 to k and djCzi:- 7 8 9. Return OPT(N) OPT[i] 1+0PT[i-dj] Was per recurrence equation =](http://img.homeworklib.com/questions/d582d9a0-7b1b-11eb-afae-15020ec97415.png?x-oss-process=image/resize,w_560)
Please comment for any clarification
1. [10 pts.] Consider the following coin changing problem. You are given a value N and...
Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 < d2 < ··· < dk, and infinitely many coins of each denomination, find the minimum number of coins needed to make exact change for n zonks. Here we ask a different problem. Each coin has a weight, the weight of each coin with denomination di being wi > 0. We want to make exact change while minimizing the total weight of the coins used....
Consider the problem of finding change using as few coins as given coins: lc, 2c, 5c. The goal is to determine the minimum number of coins that add up possible. Formally we are input non-negative integer n, and we have unlimited quantities of 3 types of as a. to nc. Your task is to design programming (a) [6 marks] Clearly define your DP states (subproblems) O(n) time algorithm for solving this problem using dynamic an (base and recursive cases) (b)...
6. Consider the following basic problem. You're given an array A consisting of n integers A[1], A[2], , Aln]. You'd like to output a two-dimensional n-by-n array B in which B[i, j] (for i <j) contains the sum of array entries Ali] through Aj]-that is, the sum A[i] Ai 1]+ .. +Alj]. (The value of array entry B[i. Λ is left unspecified whenever i >j, so it doesn't matter what is output for these values.) Here's a simple algorithm to...
Making Change: Given coins of denominations (value) 1 = v1 <
v2< … < vn, we wish to make change for an amount A using as
few coins as possible. Assume that vi’s and A are integers. Since
v1= 1 there will always be a solution.
Formally, an algorithm for this problem should take as input:
An array V where V[i] is the value of the coin of the ith
denomination.
A value A which is the amount...
Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply of quarters, nickels, dimes, and pennies. Find the minimum number of coins. Display the quantity of each coin and the total number of coins, similar to the example output below. Use global constant identifiers, of type unsigned int, for the values of quarters, nickels, dimes, and pennies. Example: const unsigned int QUARTER = 25: Do not use...
Consider the problem where you are given an array of n digits
[di] and a positive integer
b, and you need to compute the value of the number in that
base.
In general, you need to compute
For example:
(1011)2 = 1(1) + 1(2) + 0(4) + 1(8) = 11;
(1021)3 = 1(1) + 2(3) + 0(9) + 1(27) = 34, and
(1023)4 = 3(1) + 2(4) + 0(16) + 1(64) = 75.
In these examples, I give the digits...
17. Consider the following algorithm: procedure Algorithm(n: positive integer; di,d2.. ,dn: distinct integers) for 1 to n-1 for 1 to n-k if ddi+ then interchange di and di+ print(k, I, d,ddn-1, dn) (a) |3 points Assume that this algorithm receives as input the integer-6 and the corresponding input sequence 41 36 27 31 17 20 Fill out the table below ds (b) 1 point Assume that the algorithm receives the same input values as in part a). Once the algo-...
(25pts) You are given two sorted lists of size m and n. Give an O(log m log n) time algorithm for computing the k-th smallest element in the union of the two lists Note that the only way you can access these values is through queries to the databases. Ina single query, you can specify a value k to one of the two databases, and the chosen database will return the k-th smallest value that it contains. Since queries are...
4. (20 pts) Consider the N-periodic square wave given by 1, 1 sns1 (a) (10 pts) What is the fundamental frequency of the signal an wheN- (b) (10 pts) Find the Fourier series coefficients X[o] and X of the signal xln when N
4. (20 pts) Consider the N-periodic square wave given by 1, 1 sns1 (a) (10 pts) What is the fundamental frequency of the signal an wheN- (b) (10 pts) Find the Fourier series coefficients X[o] and X...
Question3 10 pts Let A [L.n] be a max-heap with n > 1 and consider the index ị such that l 〈 i 〈 n . Assume that all the elements of A are distinct. Write the pseudocode of an algorithm which replaces A [i] by A i 100 and then re-arranges the elements of A into a max-heap. The running time of your algorithm must be O (log, n Upload Choose a File
Question3 10 pts Let A [L.n]...