先决条件–渐进符号,渐进符号的性质
1.大哦符号(O) :
大哦符号用于描述渐近上限。
从数学上讲,如果f(n)描述算法的运行时间;如果存在正常数C,则f(n)为O(g(n))且不存在
0 <=f(n) <= c g(n) for all n>=n0
n =用于给上限提供一个函数。
如果一个函数为O(n),它也将自动为O(n-square)!
Big oh(O)的图形示例:
2.大欧米符号(Ω):
就像O符号提供渐近上限一样,Ω符号提供渐近下限。
令f(n)定义算法的运行时间;
如果存在正常数C和(n 0)使得f(n)为Ω(g(n))
O<= C g(n) <= f(n) for all n>=n 0
n =用于给定函数的下限
如果一个函数是O(n-square),它也会自动成为O(n)。
大欧米茄(Ω)的图形示例:
3.大Theta表示法(Θ):
令f(n)定义算法的运行时间。
如果f(n)为O(g(n))并且f(n)为Ω(g(n)),则f(n)称为Θ(g(n))。
数学上
O<=f(n)<=C 1 g(n) for n>=n 0
O<= C 2 g(n)<=f(n) for n >=n 0
合并这两个方程,我们得到:
O<=C 2 g(n)<=f(n)<=C 1 g(n) for n>=n 0
该方程式简单地意味着存在正常数C 1和C 2,使得f(n)夹在C 2 g(n)和C 1 g(n)之间。
大Theta(Θ)的图形示例:
Big oh,Big Omega和Big Theta之间的区别:
S.No. |
Big Oh |
Big Omega |
Big Theta |
---|---|---|---|
1. | It is like <= rate of growth of an algorithm is less than or equal to a specific value |
It is like >= rate of growth is greater than or equal to a specified value |
It is like == meaning the rate of growth is equal to a specified value |
2. | The upper bound of algorithm is represented by Big O notation. Only the above function is bounded by Big O. asymptotic upper bond is it given by Big O notation. | The algorithm’s lower bound is represented by Omega notation. The asymptotic lower bond is given by Omega notation | The bounding of function from above and below is represented by theta notation. The exact asymptotic behavior is done by this theta notation. |
3. | Big oh (O) – Worst case | Big Omega (Ω) – Best case | Big Theta (Θ) – Average case |
4. | Big-O is a measure of the longest amount of time it could possibly take for the algorithm to complete. | Big- Ω is take a small amount of time as compare to Big-O it could possibly take for the algorithm to complete. | Big- Θ is take very short amount of time as compare to Big-O and Big-? it could possibly take for the algorithm to complete. |
5. | Mathematically – Big Oh is 0 <=f(n) <= c g(n) for all n>=n0 | Mathematically – Big Omega is O<= C g(n) <= f(n) for all n>=n 0 | Mathematically – Big Theta is O<=C 2 g(n)<=f(n)<=C 1 g(n) for n>=n 0 |