Download presentation
Presentation is loading. Please wait.
Published byGertrude Goodman Modified over 9 years ago
1
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf (ab_sarraf@aut.ac.ir) Order Analysis, revisited
2
Dept. of Computer Eng. & IT, Amirkabir University of Technology پيچيدگي زماني الگوريتم زير کدام است؟ sum = 0; for ( i = 0; i < n; i++ ) for ( j = 0; j < i; j++ ) for ( k = 0; k < 3; k++ ) sum++; 1)O(n 3 ) 2)O(n) 3)O(nlogn) 4)O(n 2 )
3
Dept. of Computer Eng. & IT, Amirkabir University of Technology تعداد دفعات تکرار دستور خط 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
Dept. of Computer Eng. & IT, Amirkabir University of Technology تابع زير براي محاسبه بزرگترين مقسوم عليه دو عدد نوشته شده است. int gcd(int a, int b) { if ( b == 0 ) return a; else return gcd(b, a mod b); } در اين صورت مي توان گفت مرتبه زماني الگوريتم........ است. 1)2) 3)4)
5
Dept. of Computer Eng. & IT, Amirkabir University of Technology يک آرايه از اعداد صحيح بصورت 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
Dept. of Computer Eng. & IT, Amirkabir University of Technology فرض کنيد زمان اجراي الگوريتمي روي n ورودي، T(n) بوده که بصورت زير تعريف مي شود : زمان اجراي الگوريتم مزبور برابر کدام گزينه است؟ 1)O(n) 2)O(nlogn) 3)O(n 3/2 ) 4)O(n 2 )
7
Dept. of Computer Eng. & IT, Amirkabir University of Technology تابع بازگشتي زير را در نظر بگيريد : int test(int n) { if ( n <= 2 ) return 1; else return test(n-2) + test(n-2); } زمان اجراي تابع فوق برابر است با : 1)2) 3)4)
8
Dept. of Computer Eng. & IT, Amirkabir University of Technology روابط بازگشتي زير را حل کنيد :
9
Dept. of Computer Eng. & IT, Amirkabir University of Technology The Master Method (from CLRS)
10
Dept. of Computer Eng. & IT, Amirkabir University of Technology Three Common Cases
11
Dept. of Computer Eng. & IT, Amirkabir University of Technology Three common cases (cont.)
12
Dept. of Computer Eng. & IT, Amirkabir University of Technology Examples
13
Dept. of Computer Eng. & IT, Amirkabir University of Technology Examples
14
Dept. of Computer Eng. & IT, Amirkabir University of Technology Always true, Never true, or Sometimes true?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.