CSE-205 Algorithms: Algorithm, Asymptotic Notation & Complexity Analysis
CSE-205 Algorithms: Algorithm, Asymptotic Notation & Complexity Analysis
Algorithms
• logN (logarithmic)
– A big problem is solved by cutting the original problem in smaller
sizes, by a constant fraction at each step
• N (linear)
– A small amount of processing is done on each input element
• N logN
– A problem is solved by dividing it into smaller problems, solving
them independently and combining the solution
• N3 (cubic)
– Processing of triples of data (triple nested loops)
• NK (polynomial)
• 2N (exponential)
– Few exponential algorithms are appropriate for practical use
log(n)
n log(n)
log(n)
n10 n3
n2
n log(n)
3n
nn
n20
2n
n10
1.1n
Average Case
Complexity
Best Case
Complexity
N
(input size)
f(n)
n0
– 2n 2 = O(n 2 ): 2n 2
≤ cn 2
2n 2
≤ cn 2
c = 2 and n0= 1
– 1000n2+1000n = O(n2):
– n = O(n2): n ≤ cn 2
cn ≥ 1 c = 1 and n0= 1
2n O n
2
2
1,000,000n 150,000 O n
2
2
5n 7 n 20 O n
2
2
2n 2 O n
3
2
n 2.1
O n
2
f(n)
c1g(n)
n0
• Complexity:
• Complexity: