Complexity Analysis

Why Performance Analysis?
2 algorithms for a task, how to find which one is better?



1. Asymptotic Analysis

What is this Asymptotic Analysis?
Does Asymptotic Analysis always work?

Worst, Average and Best Case

Asymptotic Notations

Asymptotic notations are mathematical tools to represent time complexity of algorithms for asymptotic analysis.

Calculating Time Complexity



2. Amortized Analysis

What is this Amortized Analysis?
Why Amortized Analysis?
How to calculate it?
Benefits:



3. Space Complexity

What is Space Complexity?



4. Complexity Classes

What are complexity classes?
Easy Problems & Hard Problems
Polynomial & Exponential Time
Decision Problem & Decision Procedure

Types of Complexity Classes

P Class
NP Class
Co-NP Class

Relationship between P, NP, Co-NP:

NP-Hard Class
NP-Complete Class

Relationship between P, NP, Co-NP, NP-Hard and NP-Complete

Does P=NP?

Pseudo-Polynomial Algorithms

What is Pseudo-polynomial?
Pseudo-polynomial and NP-Completeness

NP-Hard Class Problems




Complexity Analysis Problems

Problem-1:
void fun(){
   int i, j;
   for (i=1; i<=n; i++)
      for (j=1; j<=log(i); j++)
         printf("GeeksforGeeks");
}
/* Θ(log 1) + Θ(log 2) + Θ(log 3) + . . . . + Θ(log n) = Θ(log n!) = Θ(nlogn)   coz n!≈nn/2 
T(n) = Θ(nlogn) */
Problem-2:
void fun(int n){
   int j = 1, i = 0;
   while (i < n){
       // Some O(1) task
       i = i + j;
       j++;
   }
}

/* The value of i is incremented by 1,2,3,4, . . . and so on 
So the value of i will be like 0, 1, 3, 6, 10, 15, . . .  : We can see that kth term will be k(k+1)/2
k(k+1)/2 = n => k2/2 = n => k = √n 
T(n) = Θ(√n) */




Next: Searching Algorithms→