










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











LECTURE 04: ALGORITHM ANALYSIS
Problem: Get Number of Steps
Solution: T(n) = 3(n ^ 2) + 3n + 3
long getOperationsCount(int n) { long counter = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) counter++; return counter; }
others
0
5
10
15
20
25
30
35
40
45
0 5 10 15 20 25 30 35 40
Time Complexity
Worst Average Best
0
10
20
30
40
50
60
70
80
90
100
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
Big O Notation
O(1) O(log(n)) O(n) O(n*log(n)) O(n^2) O(2^n)
Below are some examples of common algorithmic grow:
Complexity Notation Description
constant O(1) n = 1 000 1-2 operations logarithmic O(log n) n = 1 000 10 operations linear O(n) n = 1 000 1 000 operations linearithmic O(n*log n) n = 1 000 10 000 operations quadratic O(n2) n = 1 000 1 000 000 operations cubic O(n3) n = 1 000 1 000 000 000 operations exponential O(n^n) n = 10 10 000 000 000 operations
10 x 10 x 10 x 10 x 10 = 100,000 combinations