Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3707554 • Letter: T

Question

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

Explanation / Answer

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