緒論演算法複雜度

來源:互聯網
上載者:User

標籤:...   int   常見   nbsp   for   div   sub   size   pre   

常見級數演算法複雜度:

1,算數級數:與末項平方同階

T(n)=1+2+3+...=n(n+1)/2=O(n2)

2,冪方級數:比冪次高出一階

T2(n)=12+22+32+...n2=n(n+1)(2n+1)/6=O(n3)

T3(n)=13+23+33+...n3=n2(n+1)2/4=O(n4)

T4(n)=14+24+34+...n4=n(n+1)(2n+1)(3n2+3n-1)/30=O(n5)

3, 幾何級數(a>1):與末項同階

Ta(n)=a0+a1+a2+...an=(an+1-1)/(a-1)=O(an)

4,收斂級數

1/1/2+1/2/3+1/3/4+...1/(n-1)/n=1-1/n=O(1)

1+1/22+...1/n2<1+1/22+...=∏2/6=O(1)

 

常見迴圈複雜度

 

for(int i=0;i<n;i++)    for(int j=0;j<n;j++)        01operation(i,j)算數級數:
∑i=0n-1=n+n...+n=n*n=O(n2)
for(int i=0;i<n;i++)    for(int j=0;j<i;j++)        01operate(i,j);
算數級數:
∑i=0n-1=0+1+2+...n=n(n-1)/2=O(n2)
for(int i=1;i<n;i<<=1)    for(int j=0;j<i;j++)        01operate(i,j);幾何級數:
1+2+4+...+2^log2(n-1)=....=O(n)

 

緒論演算法複雜度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.