views:

519

answers:

5

Hi every one. I have this question, and I don't know how to solve it, because I don't understand it. :(

The question is:

Programs A and B are analyzed and are found to have worst case running times no greater than 150n log n and n2, respectively. Answer the following questions:

i) Which program has the better guarantee on the running time for large values of n (n > 10000)?

ii) Which program has the better guarantee on the running time for small values of n (n < 100)?

Can any one help me and explain it for me?

+3  A: 

You're given two formulae and two different values of n to plug into them. Then you're asked which formula has the larger value in each case.

I suggest plugging the two values of n into the formulae and figuring out which is larger in each case.

Michael Myers
You have say that "plugging the two values of n into the formulae and figuring out which is larger in each case".Now, when I solve it I have find the furmula (150n log n) has the larger value in the two cases ,look:In the first part [i] if I choose the number 11000 which is > 10000 , I have calculate it in the two farmulas and I find the (150n log n) has the larger value.In the second part[ii] I have choose the number 99 which is < 100 , and I find the (150n log n) has the larger value too.Have I got a correct understanding ?Sorry, but our teacher never explain it :(
Youki
150*11000*log(11000) is far smaller than 11000*11000, actually. Try calculating it again.
Michael Myers
obss, H have missing somthing.U R right .I have tried again and I find the furmula (N^2) has the larger value .
Youki
A: 

Worst case run time means the absolute longest the program will run given an input of length n. So the two formulas you were given are their worst case run times. Mathematically, both formulas behave differently at different sizes of n. Experiment with the size of n and see how they respond. That will help you understand and find your answers.

Poindexter
I have doing what do you say :when I solve it I have find the furmula (150n log n) has the larger value in the two cases ,look: In the first part [i] if I choose the number 11000 which is > 10000 , I have calculate it in the two farmulas and I find the (150n log n) has the larger value. In the second part[ii] I have choose the number 99 which is < 100 , and I find the (150n log n) has the larger value too
Youki
A: 

See yourself at WolframAlpha. The point where the worst cases are equal is circa at 1042. That should answer your question.

Johannes Weiß
Since this is algorithms homework, log is likely base 2 and not the natural logarithm.
bcat
I have see the graph .. Do u want to say that the (150n log n) has the big value ?
Youki
Strange! For 0<=n<1402: 150*n*log(n) > n^2; for 1402<=n: 150*n*log(n) < n^2
Johannes Weiß
A: 

If the actual question is O(n^2), ii is a trick question.

In Big-O notation, you can drop constants, so O(10000n^2) is the same as O(n^2). If you haven't removed the O() from the question, then just fill in the equations, that shouldn't be hard to work out.

Dean J
but it dis'nt want the Big O notation .. I have confusssed :(
Youki
A: 

Have you looked at a graph of the two complexity functions?

bcat
you mean the first case , is't it ?
Youki