Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

what is the role of the constant of proportionality while comparing the the order of complexities of two competing algorithms.

Like in case ALGO A has complexity 3*O(n) while ALGO B has complexity 10*O(n),What will be the effect of constant of 3 and 10 here?

share|improve this question
add comment

3 Answers

The constants have no effect at all -- "$3\cdot O(n)$ and "$10\cdot O(n)$" both describe the same class of functions.

share|improve this answer
add comment

The definition of f=O(g) is that there exists an n,m such that for every x>n, f(x) < M*g(x). that's why the constant doesn't matter. suppose ALGO A runs in 2*n binary operations, while ALGO B runs in n binary operations. then both run in O(n) time complexity.

share|improve this answer
    
so what is the difference between ALGO A and B ??? –  coder Apr 19 '12 at 12:12
1  
This is hard to tell, since $3 \cdot O(n) = 10 \cdot O(n)$. The only thing we can say is that the algorithms take roughly linear time in the size of the input. –  Johannes Kloos Apr 19 '12 at 12:19
1  
@JohannesKloos: Strictly speaking, roughly linear time would be $\Theta(n)$, not $O(n)$. –  Aryabhata Apr 19 '12 at 16:48
1  
@Aryabhata: True, but that was roughly what I meant by "roughly" :) I tend to assume that an algorithm will consume all its input, so it will have $\Omega(n)$ time-complexity. –  Johannes Kloos Apr 19 '12 at 17:36
1  
@JohannesKloos: So, do you hate binary-search? :-) Just kidding... –  Aryabhata Apr 19 '12 at 18:07
show 1 more comment

you can judge the importance of constant of proportionality by comparing insertion sort (c1.n^2),and merge sort(c2.nlogn). insertion sort is better when n is small,because of only single reason ie c1

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.