views:

148

answers:

3

1) Reorder the following efficiency from smallest to largest: 2^n, n!, n^5, 10000, nlog2(n)

My Ans-> 10000 < nlog2(n) < n^5 < 2^n < n! Correct ?

2) Efficiency of an algo. is n^3, if a step in this algo. takes 1 nanosec. (10^-9 sec.). How long does it take the algo. to process an input of size 1000?

I don't know ... Is it (1000)^3 * 10^-9 ?

+1  A: 

Both answers are correct

Kip
+1  A: 

1) Yes, that's correct.

2) That is also correct. Dimensional analysis: (1000^3 steps) * 10^(-9) seconds/step

Jeremy Powell
+2  A: 

Question one is fine. Question two, I would guess your answer is what they're looking for, but if by n^3 you mean O(n^3), you can't actually answer it (unless this is a use of "algorithmic efficiency" I'm unfamiliar with).

Big-O complexity gives an asymptotic bound on the behavior of the algorithm. We know, for "large" n, that O(n^3) is larger than the time taken to execute the algorithm on input of size n. Note the two caveats - "large n" and "asymptotic bound". There's nothing to stop an input of size 1000 taking twice as long as an input of size 2000, as long as there exists some m such that for all n > m, n^3 bounds the runtime. Also, there's nothing to stop the algorithm taking 1 nanosecond on every input, as n^3 is still a bound on the runtime - it's just very pessimistic.

This is why big O notation is often of limited use in practical situations. It gives a fair "worst case" overview, but does not speak to any given usage scenario. For a more practically useful (but often overlooked) complexity class set, google for "Big theta".

Adam Wright
In the definition of big-O the scaling factor is also important; it'd more technically correct to say "as long as there exist constants *m* and *k* such that for all *n* > *m*, *k n*³ bounds the runtime."Big-theta is great, but I don't think the practical use of big-O is limited by the fact that it's usually used to refer to a tight bound even though it doesn't strictly require it. It's easier, and sometimes the math on a true theta bound is too hairy to be worth it.
jtb
good point, #2 is technically unanswerable from the information given, although I'd guess the writers of the question wanted just the answer he provided. :-/
Kip
Yes, there is a scaling factor - I left it out deliberately, to avoid even more confusion for the questioner, but thanks for mentioning it :)
Adam Wright
I was asked a similar question to #2 in a tutorial some years ago. I was in the group that answered the same was as Thura did ... and we were gently corrected by the tutor :-) +1
John Fouhy