0

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

3
Contributors
4
Replies
11
Views
6 Years
Discussion Span
Last Post by vinitmittal2008
0

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.

1

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 by vinitmittal2008: n/a

Votes + Comments
Thanksss
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.