Sunday, April 14, 2013

Answer - Which one is faster ?

The question asked on my post which-one-is-faster

Here is the answer to that question.
If we consider compare and increment part, it becomes clear that which one is faster and how ?

Compare :
Problem -1 has (10000*11)+10001 = 120001 comparisons
Problem-2 has (10*10001)+11 = 100021 comparisons
Delta = 120001 – 100021 = 19980

Increment:
Prblem-1 has (10000*10)+10000 = 110000 increments
Problem-2 has (10*10000)+10 = 100010 increments
Delta = 110000-100010 = 9990
So problem-2 is faster !!

No comments:

Post a Comment