THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE!
You have a set of N coins in a bag, each having a value between 1 and M, where M ? N. Some coins may have the same value. You pick two coins (without replacement) and record the sum of their values. Determine(algorithm ) what possible sums can be achieved, in O(M log M ) time.
For example, if there are N = 3 coins in the bag with values 1, 4 and 5 (so we could have M = 5), then the possible sums are 5, 6 and 9.
(if the coins have values v1,...,vN, how might you use the polynomial xv1 +···+xvN? )
ANSWER:
]Now if you compute f(x)*f(x) it would be
( x^1 + x^4 + x^5) * ( x^1 + x^4 + x^5) = x^2 + x^5 + x^6 + x^5 + x^8 + x^9+x^6 + x^9 + x^10 = x^2 + 2x^5 + 2x^6 + x^8 + 2x^9 + x^10
Places where the coefficient is greater then 1 are the result of choosing different coefficients. If you collect powers of the terms where coefficient is 2 are 5, 6, and 9 which is our answer.
So the solution is as below.
step-01: make a polynomial by placing all the coin values to the power of x. This step would take O(M) time.
step-02: Find square of the polynomial cumputed as above using FFT (fast fourier transform). It would take O(M log M) time
THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins...
Suppose you have a set of coins of various denominations, with values v1, v2, …, vn. Some of the coins may have the same value as other of the coins (or maybe not, for the purpose of this problem it doesn’t matter). I want to use these to buy an item that costs exactly M. That is, I want to find out if there is some subset of the coins whose values will sum to exactly M. (Note that I...
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...
Consider there is a row of n coins and you and a friend are playing a game (note: n is even). On your turn you can pick either the left most or the right most coin. Once you take a coin, a new coin is exposed. You have perfect information about what coins are available. Design an algorithm which gets you the maximum amount of money possible. Assume your friend is as clever as you are.
Assume you have a necklace of stones. Some of the stones have positive value and some have negative value. You have the opportunity to snip the necklace in two places (creating two bands) and weld the endpoints of one of the two bands back into a necklace. You would like your new necklace to be as valuable as possible. You can assume the necklace has n stones with values O,,vn-1. (1) Give an efficient algorithm to find the value of...
(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...
In this assignment, you will prove that the Zero Sum problem is NP-Complete. The Zero Sum problem accepts an array of n integers and returns whether it is possible to negate some of those integers to make the array sum equal 0. For example, the array data = [1, 3, 5, 7, 9, 11] has a zero sum if you negate the 7 and 11, while the array data = [1, 2, 5, 9, 13, 22] cannot be reduced to...
7. You have 5 algorithms, Al took O(n) steps, A2 took ©n log n) steps, and A3 took 2(n) steps, A4 took O(ny) steps, A5 took on?) steps. You had been given the exact running time of each algorithm, but unfortunately you lost the record. In your messy desk you found the following formulas: (e) 7n! (f) 23 logan (g) 22 log2 n For each algorithm write down all the possible formulas that could be associated with it.
We have a function F : {0, . . . , n − 1} → {0, . . . , m − 1}. We know that, for 0 ≤ x, y ≤ n − 1, F((x + y) mod n) = (F(x) + F(y)) mod m. The only way we have for evaluating F is to use a lookup table that stores the values of F. Unfortunately, an Evil Adversary has changed the value of 1/5 of the table entries...
Consider n indivisible objects with distinct types i = 1, 2, 3,…, n. We are given positive integer weights W = {w1,w2...wn} and positive integer prices V = {v1,v2...vn} for the objects and a knapsack of weight capacity (m). Our problem is to find the maximum profit possible by including a subset of the objects into the knapsack with total weight of at most m. This form of the 0/1 Knapsack Problem can be solved by a Decrease and Conquer...
(1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an integer between 1 and n. (2) Suppose Algorithm-1 does f(n) = n**2 + 4n steps in the worst case, and Algorithm-2 does g(n) = 29n + 3 steps in the worst case, for inputs of size n. For what input sizes is Algorithm-1 faster than Algorithm-2 (in the worst case)? (3) Prove or disprove: SUM{i**2} [where i changes from i=1 to i=n] ϵ tetha(n**2)....