Question

THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins...

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? )

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
THIS QUESTION MUST BE ANWSERD WITH CLEAR ENGLISH PSEUDOCODE! You have a set of N coins...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we...

    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...

    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...

    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...

    (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...

  • 7. You have 5 algorithms, Al took O(n) steps, A2 took ©n log n) steps, and...

    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,...

    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...

  • (1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an...

    (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)....

  • In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Cons...

    In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be 0-red. 1-yellow, 2-blue, 3-pink. , c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collect...

    In terms of the programming language required, the algorithm needs to be written in pseudocode Dynamic Programming Consider the following problem based on the transformation of a sequence (or collection) of coloured disks Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, c. For example, the colour mapping might be 0-red. 1-yellow, 2-blue, 3-pink. , c-black For a given sequence of coloured disks e.g., ( 0,1,2,3,4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT