第二章 Big O notation,第二章bignotation

來源:互聯網
上載者:User

第二章 Big O notation,第二章bignotation


第二章 

Big O notation

電腦的計算過程中,基本上都是一些複雜的計算,數以千計,數以萬計或是數以億計的計算,那麼如何計算和總結為讓我們更加簡單易懂的語言呢,與成績分層是一個道理,A是好的,B次好等等等等,那麼我們就引入了big O notation這個概念。
在這裡,我們程式員如果要進行編程,我們不希望電腦花費大量的時間去進行一個運算,對於我們和使用者來說,我們要盡全力將big O 弄到最小。
1,2,3,4,5,6,7的是O(1),是屬於常數的n,2n,2n+1,4m+4的是O(n),是屬於線性函數n^2 4n^2+3等等的話就是O(n^2),二次的線性函數等等
那麼,如果一個函數它是以多項式來表示的,那麼他的big O notation是什麼呢?給大家一個我們學校的例子,
當我們要看一個多項式的時候,General rule,pick the term that grows the fastest and remove
the constants from it:5n + 2log(n) is O(n).
3n^3 +2^n/6 is O(2^n ).
8log(n) + 7n is O(n).

從增長速度最小到速度最快:loglogn
logn (logarithmic)
sqrt n
n (linear)
n log(n)
n^2 (quadratic)
n^3 (cubic)
...
n^k (polynomial hierarchy)
a^n (exponential hierarchy)
n!

以上是big o notation的基礎,下一期我會詳細的介紹到執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.