Professional Documents
Culture Documents
ANALYSIS OF ALGORITHMS
RAZA ABBAS
13K-2023
M. UMER JAVED
13K-2161
AKHLAAK AHMED KHAN
13K-2017
Big O Notation
Big O Notation is a mathematical tool which tells us
Experimental Approach
There may be the experimental approach of
Example of Experimentation
Lets take an example of printing n numbers.
for(int i = 0; i < n; i++) {
System.out.print(i);
}
The input given is one million.
On one computer, it took 1.2 seconds while on other, it
took 2 seconds...
Time in MS
100000
90000
80000
70000
60000
PC 1
PC 2
50000
40000
30000
20000
10000
0
10000
20000
30000
40000
50000
60000
Theoretical Approach
Here comes the need of Big O Notation. The Big O
Example
Again take the same example.
for(int i = 0; i < n; i++) {
System.out.print(i);
}
Lets say, that comparison and assignments take one unit of
time, and printing also takes one unit.
In our case, the whole algorithm took 1+n+1+n+n.
Hence, 3n+2.
We can approximate this as n, because constants doesnt
make any big difference in our time.
So the Big O Notation of our algorithm is O(n).
Slight difference
10,000
1,000
100
10
3n
2n
+
10
n
1
1
10
100
1,000
logn
nlogn
n2
n3
2n
16
64
16
24
64
512
256
16
16
64
256
4,096
65,536
32
32
160
1,024
32,768
4,294,967,296
64
64
384
4,094
262,144
1.84 * 1019
128
128
896
16,384
2,097,152
3.40 * 1038
256
256
2,048
65,536
16,777,216
1.15 * 1077
512
512
4,608
262,144
134,217,728
1.34 * 10154
1024
10
1,024
10,240
1,048,576
1,073,741,824
1.79 * 10308