I want to know the procedure by which we can calculate time complexity of a C program.
and how would we compare two algorithms.

here are two sorting programs. how to compare both.

for(i = 0; i < n - 1; i++)
    for(j = i + 1; j < n; j++)
      if(num[i] > num[j])
       {
	   temp   = num[i];
	   num[i] = num[j];
	   num[j] = temp;
       }
for(i = n - 1; i >= 0; i--)
    for( j = 0; j < i; j++)
       if(num[j] > num[j+1])
       {
	   temp = num[j];
	   num[j] = num[j+1];
	   num[j+1] = temp;
       }

Thanks

If you wanted to compare the raw speed of two algorithms on a specific system, you just run them a few thousand times and get the recorded run time difference.

For that you need a good knowledge of programming, like you need to know worst case complexity, best case complexity and Average time complexity.
Read This

Edited 5 Years Ago by vinitmittal2008: n/a

Comments
Thanksss
This question has already been answered. Start a new discussion instead.