I saw an example function for some unknown algorithm in a book that was explaining big theta/o/omega notation. I understand how it all works, but this example is throwing me off:

f(n) = 3n^2-2n-10

And what I'm wondering is this: What kind of operation could you possibly do that would produce a negative coeffecient? I can't think of any, but maybe I'm missing something. If someone could show me a bit of pseudo-code or something that would produce a negative coeffecient on the amount if time it takes to run as a function of the number of inputs it would make me sleep better tonight..thanks.

-Fredric

Suppose you've got

for (i = 0; i < N + 1; ++i) {
    for (j = 0; i < N - 2; ++j) {
        some_constant_time_function(i,j);
    }
}

The total number of times some_constant_time_function() would be called is (N + 1)*(N - 2), is it not? Which expands to N^2 - N - 2.

Hehe, ok, that makes sense.

Thank you. :o

-Fredric

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.