简体   繁体   中英

Analyse of an algorithm (N^2)

I need to run an algorithm with worst-case runtime Θ(n^2). After that I need to run an algorithm 5 times with a runtime of Θ(n^2) every time it runs.

What is the combined worst-case runtime of these algorithms ?

In my head, the formula will look something like this:

( N^2 + (N^2 * 5) )

But when I've to analyse it in theta notation my guess is that it runs in Θ(n^2) time.

Am I right?

Two times O(N^2) is still O(N^2), ten times O(N^2) is still O(N^2), five times O(N^2) is still O(N^2), any times O(N^2) is still O(N^2) as long as 'any' is a constant.

Same answer holds for \\Theta instead of O.

It is O(n^2) regardless because what you have is basically O(6n^2) , which is still O(n^2) because you can ignore the constant. What you're looking at is something that belongs to a set of functions and not the function itself.

Essentially, 6n^2 ∈ O(n^2) .

EDIT

You asked about Θ as well. Θ gives you the lower and upper bound, whereas O gives you the upper bound only. You only get the lower bound with Ω. Θ is the intersection of these two.

Anything that is Θ(f(n)) is also O(f(n)) , but not the other way round.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM