L2 (3)
L2 (3)
فصل دوم
فهرست مطالب
مقدمهای بر الگوریتمها و مفاهیم پایه
معرفی پیچیدگی زمانی و حافظهای و روشهای تحلیل مسائل
روش های حل مسئله
تقسیم و غلبه (حل)
برنامه نویسی پویا
روش حریصانه
راهبرد عقبگرد
شاخه و حد
آشنایی نظریه NPو مسائل مربوط به آن
3
Analysis of Algorithms
• Different input requires different amount of resources. Instead of
dealing with input itself, we prefer to deal with the Size of Input.
Practical Complexity
250
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
8
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
9
1000
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1 3 5 7 9 11 13 15 17 19
10
5000
4000
f(n) = n
f(n) = log(n)
3000
f(n) = n log(n)
f(n) = n^2
2000 f(n) = n^3
f(n) = 2^n
1000
0
1 3 5 7 9 11 13 15 17 19
11
Notation
12
Notation (Cont.)
13
Notation (Cont.)
14
Notation (Cont.)
15
Notation (Cont.)
• Examples
▫ 3n+2=O(n) /* 3n+24n for n2 */
▫ 3n+3=O(n) /* 3n+34n for n3 */
▫ 100n+6=O(n) /* 100n+6101n for n10 */
▫ 10n2+4n+2=O(n2) /* 10n2+4n+211n2 for n5 */
▫ 6*2n+n2=O(2n) /* 6*2n+n2 7*2n for n4 */
16
Notation (Cont.)
• O(1): constant
• O(n): linear
• O(n2): quadratic
• O(n3): cubic
• O(2n): exponential
• O(logn): logarithmic
• O(nlogn): log linear
17
Notation (Cont.)
18
Homework …