views:

447

answers:

2

I'm attempting to guess and prove the Big O for:

f(n) = n^3 - 7n^2 + nlg(n) + 10

I guess that big O is n^3 as it is the term with the largest order of growth

However, I'm having trouble proving it. My unsuccesful attempt follows:

f(n) <= cg(n)
f(n) <= n^3 - 7n^2 + nlg(n) + 10 <= cn^3 
f(n) <= n^3 + (n^3)*lg(n) + 10n^3 <= cn^3
f(n) <= N^3(11 + lg(n)) <= cn^3

so 11 + lg(n) = c

But this can't be right because c must be constant. What am I doing wrong?

+8  A: 

For any base b, we know that there always exists an n0 > 0 such that

log(n)/log(b) < n whenever n >= n0

Thus,

n^3 - 7n^2 + nlg(n) + 10 < n^3 - 7n^2 + n^2 + 10 when n >= n0.

You can solve from there.

rlbond
Nice and simple. +1.
danben
Thanks, that was the missing link in my understanding.
halohunter
A: 

For your question, the proof of O(n^3) should look something like this:

f(n) <= n^3 + 7n^2 + nlg(n) + 10 for (n > 0)
f(n) <= n^3 + 7n^3 + nlg(n) + 10 for (n > 0)
f(n) <= n^3 + 7n^3 + n*n^2 + 10  for (n > 2)
f(n) <= n^3 + 7n^3 + n^3 + 10  for (n > 2)
f(n) <= n^3 + 7n^3 + n^3 + n^3 for (n > 3)
f(n) <= 10n^3 for (n > 3)

Therefore f(n) is O(n^3) for n > 3 and k = 10.

Kevin Sylvestre
Solving problems that are likely homework is generally discouraged.
danben
@danben: I don't think so. Even though many think it should be, there are also many who take the view that questions should just be answered, not ifs and buts.
Svante
It is fine to answer a question, rather than hinting at the solution, but the answer should further the OP's understanding of the problem domain. This answer doesn't help the OP at all, short of cut and pasting it into his or her homework assignment.
rjh
@Svante - Here is a link to the guidelines (that are in turn linked by the faq): http://meta.stackoverflow.com/questions/10811/homework-on-stackoverflow
danben
@danben: that answer is neither official nor binding. I just don't see the "generally". Sure, I usually would not completely solve homework for others either, but I will definitely not downvote correct answers.
Svante
@Svante: I don't know what you mean by "binding", but if you require something being a bannable offense before you refrain from doing it, then you are being a jerk. No offense. As far as it not being "official", Joel states in that very sentence that it is not "official" in terms of being sent down by the moderators, but instead was written as the result of a collective effort of the community. So that is where "generally" comes from. Also, no one said anything about downvoting until you did just now.
danben
Sorry this was such a controversial answer. The original question was not tagged as homework, however my judgement should have led me to believe it was indeed homework. Once again, my apologies; I'll be sure to consult the FAQ in the future.
Kevin Sylvestre
@Kevin Syvestre: No need to apologize. @danben: I already said that _I_ would not answer like this, but I am deeply convinced that anyone has the _right_ to do so. I mentioned downvoting because this answer is now +2/-2, which is, in view of a correct and helpful answer, ridiculous behaviour by the downvoters.
Svante
"You are being a jerk" is definitely offensive, by the way. If you think you can meaningfully tell someone else not to be offended by an offense, you are a jerk.
Svante
@Svante: perhaps you should have read the whole sentence, rather than just the last few words.
danben