theta符号
Big Omega tells us the lower bound of the runtime of a function, and Big O tells us the upper bound.
Big Omega告诉我们函数运行时的下限,Big O告诉我们上限。
Often times, they are different and we can’t put a guarantee on the runtime - it will vary between the two bounds and the inputs. But what happens when they’re the same? Then we can give a theta (Θ) bound - our function will run in that time, no matter what input we give it.
通常,它们是不同的,我们不能保证运行时-它在两个范围和输入之间会有所不同。 但是,当它们相同时会发生什么呢? 然后,我们可以给定theta (θ)界限-无论我们给它什么输入,我们的函数都会在那个时候运行。
In general, we always want to give a theta bound if possible because it is the most accurate and tightest bound. If we can’t give a theta bound, the next best thing is the tightest O bound possible.
通常,如果可能的话,我们总是希望给出theta界限,因为它是最准确,最严格的界限。 如果我们不能给定theta界限,那么下一个最好的事情就是尽可能严格的O界限。
Take, for example, a function that searches an array for the value 0:
以一个在数组中搜索值0的函数为例:
def containsZero(arr): #assume normal array of length n with no edge cases
for num x in arr:
if x == 0:
return true
return false
- What’s the best case? Well, if the array we give it has 0 as the first value, it will take constan