An algorithm can be analyzed in two ways. One is the time it takes and the second is the space it takes.

Time Complexity:- In computer science, the time complexity is the number of operations done by the operating system from the start of the algorithm to the end of the algorithm.

Space complexity:- The amount of space or the number of bits required to solve a problem is referred to as its space complexity.

If we have two algorithms A1 and A2 for a problem, we want to know which one takes the least amount of time. Our problem is not the space taken by that algorithm. In today’s world, space is unlimited. Our problem is the time. Time is valuable.

Worst Case Complexity-

It is the maximum time taken by an algorithm to solve a problem.

Best Case Complexity-

It is the minimum time taken by an algorithm to solve a problem.

Average Case Complexity-

It is in between the best case and worst case.

This means the average time is taken by an algorithm to solve a problem.


Time Complexity of a code

Code  Number of Operations
int main()                           ............. 1
                                          ............. 1
int p = 1, sum = 0, n=10;   ............. 1

for (p=1; p<=n; p++)          ............

{

    sum = sum + p;             

}   

n
printf(sum);                       ............ 1
Sum of time complexity of different steps = 1 + 1 + 1 + n + 1 
So, time complexity is equal to n + 4
but we remove constant as constant will not play a big role of time complexity if n is so large.
Time Complexity of the code is O(n).