[英]Analyse of an algorithm (N^2)
I need to run an algorithm with worst-case runtime Θ(n^2). 我需要以最坏情况的运行时间Θ(n ^ 2)运行算法。 After that I need to run an algorithm 5 times with a runtime of Θ(n^2) every time it runs.
之后,我需要每次运行5次,每次运行时的运行时间为Θ(n ^ 2)。
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. 但是,当我必须以theta表示法对其进行分析时,我的猜测是它在Θ(n ^ 2)时间内运行。
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. 两次O(N ^ 2)仍为O(N ^ 2),十次O(N ^ 2)仍为O(N ^ 2),五次O(N ^ 2)仍为O(N ^ 2) ,只要'any'是常数,O(N ^ 2)仍然是O(N ^ 2)即可。
Same answer holds for \\Theta instead of O. \\ Theta而不是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. 它是
O(n^2)
因为您所拥有的基本上是O(6n^2)
,仍然是O(n^2)
因为您可以忽略该常数。 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)
. 本质上,
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.
Θ给您下限和上限,而O仅给您上限。 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. 等于
Θ(f(n))
的也是O(f(n))
,但反之亦然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.