Slide 7 - Time Complexity
Slide 7 - Time Complexity
1
Every extraordinary feet began in ordinary circumstances. I will start my journey of success from where I am now.
License
2
Linear Time
How to find the biggest number from a list of N numbers
A1 A2 A3 ………………. AN
• MAX = A1
• i=1 //2
• WHILE (i <= N)
• IF (Ai > MAX)
• MAX = Ai
• i=i+1
• PRINT MAX
• STOP
3
Different Search Technique
Elements : 11 13 33 45 56 64 73
1. Linear Search
2. Binary Search
4
Different Cases
1. Worst Case
2. Best Case
3. Average Case
5
Time Complexity of Binary Search
Elements : 11 13 33 45 56 64 73
•N
• N/2
N / 2k = 1
• N/4 Þ N = 2k
. Þ 2k = N
.
Þ log2 2k = log2N
.
Þ k = log2N
• Until the list size is 1
6
Complexity
1. Linear Complexity
2. Logarithm Complexity
3. N2 or N3 Complexity
4. 2N Complexity
7
Quadratic Time Complexity (N2)
Make a pair on this element
• i=1
• WHILE (i <= N)
• j=1
• WHILE (j <= N)
• PRINT Ai Aj
• j++
• i++
• STOP
8
Time Complexity : Where is Time?
9
Big O Notation
N2+2N+1 = O(N2)
10
Big O Example
13
Big O Example
15
Big O Example
16
Big Omega Notation
N2+5n = (N2)
17