考虑到所有的根,我怎么找到一个多项式的系数时间为O快(N ^ 2)?多项式、有的、考虑到、时间为

2023-09-11 23:19:05 作者:▍你最珍贵 〆

给出一个多项式的所有根,我必须搞清楚一个算法产生的系数比为O(n ^ 2)速度更快。我无法处理这个问题。我是pretty的肯定,我应该使用一个快速傅立叶变换的概念或傅立叶逆变换,但我不知道如何修改输入不团结的第n个根。任何人都可以点我朝着正确的方向?

解决方案

kraskevich基本上钉它。一些细节丢失,这将是太长,不适合到注释字段。下面是详细信息。

基本上,你要建立一个多项式乘法问题。您的意见将是P1,... PN其中,PJ(X)=(X-RJ)。

下面是伪code:

函数multiply2Poly(P1,P2)    //这里,使用FFT,乘,使用IFFT回 功能multiplyPoly(第[1],... P [N])     如果(N == 1)返回P [1]     如果(N == 2)返回multiply2Poly(第[1],第[2])     其他 {          返回multiply2Poly(multiplyPoly(第[1],... P [N / 2]),multiplyPoly(第[1 + N / 2],...,P [N])     } 功能getCoef(R [1],...ř[N])     返回multiplyPoly((第[1] = XR [1]),...(P [N] = XR [N]));

而对于FFT部分:

注意,如果两个多项式是:

  P1 = A [0] + A [1]×+ ... + A [N]×n次方
P2 = B [0] +一[1]×... +一[]×n次方
 
比特币的数学原理

然后P1 * P2 = C [0] + C [1]×+ ... + C [N]×n次方

其中C = A [X] B,其中[X] =卷积。 A =(一个[0],...,A [n])的,B =(B [0],...,B [n]的)和C =(C [0],...,C [ N])。

然后使用FFT和卷积定理加快这。

C = A [X] B = {IFFT FFT {A} * FFT {B}},其中*这里只是乘法。

IFFT的运行时间= FFT的运行时间=为O(n log n)的。照片 乘法的运行时间为n,所以总的运行时间为O(n log n)的。

multiplyPoly的总运行时间则为:

T(N)= R(N / 2)+ T(N / 2)* 2

和R(N / 2)=为O(n log n)的是multiply2Poly的运行时间,如上所述。

所以

T(N)= T(N / 2)×2 + O(N日志N)

和现在的主定理给出了为O(n(log n)的^ 2)

Given all the roots of a polynomial, I have to figure out an algorithm that generates the coefficients faster than O(n^2). I'm having trouble approaching this problem. I'm pretty sure I'm supposed to use the concept of a Fast Fourier Transform or Inverse Fourier Transform, but I don't know how to modify the input to not be the nth roots of unity. Can anyone point me in the right direction?

解决方案

kraskevich basically nailed it. Some details are missing, and it would be too long to fit into the comment field. Here are the details.

Basically, you want to set up as a polynomial multiplication problem. Your input would be p1,...pN where pj(x) = (x-rj).

Here's pseudo-code:

function multiply2Poly(p1, p2)

   // here, use FFT, multiply and use IFFT back


function multiplyPoly(p[1],...p[N])
    if (N==1) return p[1]
    if (N==2) return multiply2Poly(p[1],p[2])
    else {
         return multiply2Poly(multiplyPoly(p[1],...p[N/2]),multiplyPoly(p[1+N/2],...,p[N])
    }


function getCoef(r[1],...r[N])

    return multiplyPoly((p[1]=x-r[1]),...(p[N]=x-r[N]));

And for the FFT part:

Observe that if two polynomials are:

p1 = a[0]+a[1] x + ...+a[n] x^n
p2 = b[0]+a[1] x + ...+a[n] x^n

Then p1 * p2 = c[0] + c[1] x + ...+c[n] x^n

where C = A [x] B where [x] = convolution. A = (a[0],...,a[n]), B = (b[0],...,b[n]) and C = (c[0],...,c[n]).

Then use FFT and the convolution theorem to speed this up.

C = A [x] B = IFFT{ FFT{A} * FFT{B} } where * here is just multiplication.

runtime of IFFT = runtime of FFT = O(n log n). multiplication run time is n, so the total run time is O(n log n).

The total run time of multiplyPoly is then:

T(N) = R(N/2) + T(N/2)*2

And R(N/2) = O(n log n) is the run time of multiply2Poly as described above.

so

T(N) = T(N/2) * 2 + O(n log n)

and now the Master theorem gives the O(n (log n)^2)