1 / 14

Order Analysis, revisited

Order Analysis, revisited. پيچيدگي زماني الگوريتم زير کدام است؟ sum = 0; for ( i = 0; i < n; i++ ) for ( j = 0; j < i; j++ ) for ( k = 0; k < 3; k++ ) sum++; O(n 3 ) O(n) O(nlogn) O(n 2 ). تعداد دفعات تکرار دستور خط 3 چندتاست؟ for ( k = 0; k <= n – 1; k++ )

smorehouse
Download Presentation

Order Analysis, revisited

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. Order Analysis, revisited

  2. پيچيدگي زماني الگوريتم زير کدام است؟ sum = 0; for ( i = 0; i < n; i++ ) for ( j = 0; j < i; j++ ) for ( k = 0; k < 3; k++ ) sum++; • O(n3) • O(n) • O(nlogn) • O(n2)

  3. تعداد دفعات تکرار دستور خط 3 چندتاست؟ for ( k = 0; k <= n – 1; k++ ) for ( i = 1; i <= n – k; i++ ) a[i][i+k] = k; 1) 2) 3) 4)

  4. تابع زير براي محاسبه بزرگترين مقسوم عليه دو عدد نوشته شده است. int gcd(int a, int b) { if ( b == 0 ) return a; else return gcd(b, a mod b); } در اين صورت مي توان گفت مرتبه زماني الگوريتم ........ است. 1) 2) 3) 4)

  5. يک آرايه از اعداد صحيح بصورت A[1..m] مفروض است، به طوريکه در اين صورت مرتبه اجراي الگوريتم زير کدام يک از گزينه هاي زير است؟ T := 0; For i := 1 to m do for j := 1 to A[i] do T := T + 1; 1) 2) 3) 4)

  6. فرض کنيد زمان اجراي الگوريتمي روي n ورودي، T(n) بوده که بصورت زير تعريف مي شود: زمان اجراي الگوريتم مزبور برابر کدام گزينه است؟ • O(n) • O(nlogn) • O(n3/2) • O(n2)

  7. تابع بازگشتي زير را در نظر بگيريد: int test(int n) { if ( n <= 2 ) return 1; else return test(n-2) + test(n-2); } زمان اجراي تابع فوق برابر است با: 1) 2) 3) 4)

  8. روابط بازگشتي زير را حل کنيد:

  9. The Master Method (from CLRS)

  10. Three Common Cases

  11. Three common cases (cont.)

  12. Examples

  13. Examples

  14. Always true, Never true, or Sometimes true?

More Related