1 / 15

BASICS 2

Office hour 改成 三 9-10. BASICS 2. Prof. Michael Tsai 2012/3/6. 作業一的程式題不容易寫呀 ! 要趕快開始 !. Definition [Omega ]: { : there exist positive constants and such that for all } “f of n is omega of g of n ” 可以想成是 Lower Bound. Asymptotic notation – Omega. since for all 1 .

Download Presentation

BASICS 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Office hour 改成三9-10 BASICS 2 Prof. Michael Tsai 2012/3/6 作業一的程式題不容易寫呀!要趕快開始!

  2. Definition [Omega]: {: there exist positive constants and such that for all } “f of n is omega of g of n” 可以想成是Lower Bound Asymptotic notation – Omega

  3. since for all 1. since for all 1. since for all . since for all 1. since for all 1. Examples for all

  4. Examples • (1) • (1) for all

  5. Omega is a lower bound. Should be as large a function as possible. Theorem: If and , then . (證明: 請自己證證看!) Discussion

  6. Definition [Theta]: {: there exist positive constants such that for all } “f of n is theta of g of n” 三明治夾心, 同時具有和 Asymptotic Notation – Theta Theta Platform GMC Terrain

  7. 用圖表示 • Big Oh • 紅色 • Omega • 藍色 • Theta • 紅色藍色都要

  8. since for all and for all . Example for all

  9. More precise than both the “big oh” and omega notations • It is true if and only g(n) is both an upper and lower bound on f(n). • Coefficient = 1 • (no good) • (ok!) • Theorem: If and , then . • (證明: 請自己證證看!) Discussion

  10. 那麼, 怎麼知道程式的時間複雜度? • 看每個statement執行幾次, 畫表來計算 • 有時候複雜度不只跟input大小不一定有關係 • (像是binary search, 跟裡面實際數字是什麼有關) • 這時候可以取 • Worst case:給一組input可以使此algorithm執行最慢; 最慢的執行時間是多少? • Best case: 給一組input可以使此algorithm執行最快; 最快的執行時間是多少? • Average case: 考慮所有case的執行時間, 平均是多少? • 實際測量程式執行時間最實際! • (但是常常不可行,此時asymptotic analysis是最好的方法)

  11. Example 1

  12. intbinsearch(int list[], intsearchnum, int left, int right) { int middle; while(left<=right) { middle=(left+right)/2; switch(COMPARE(list[middle], searchnum)) { case -1: left=middle+1; break; case 0: return middle; case 1: right=middle-1; } } return -1; } Example 2

  13. Worst case: Best case: searchnum=13; 0 1 2 3 4 5 6 7 8 9 10 11 1 3 4 4 7 11 13 13 13 18 19 6 right left middle middle=(left+right)/2; left=middle+1; Half the searching window every iteration.

  14. 兜基??

  15. n很大的時候右邊比左邊好 但是n會很大嗎? 有時候不會 如果n永遠小於 ?? 結論:要看n大小 (實際上寫程式的時候適用) 哪一個好…

More Related