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;


ohh.. That means there is no easy way to compare two algorithms.

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

commented: Thanksss +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.