首页
友链
关于

数据结构与算法 课堂笔记 3:算法复杂度(Program Complexities)

03 / 13 / 2023 (最后编辑于 03 / 13 / 2023)
预计阅读时间 5 分钟

Asymptotic Analysis

Worst case Analysis

Average case Analysis

Best case Analysis

Asymptotic Notation

OO-notation

O(g(n))={f(n)  c, n0>0, 0f(n)cg(n), nn0}Ο(g(n)) = \left\{f(n)\ |\ \exist c,\ n_0 \gt 0,\ 0 \le f(n) \le cg(n),\ \forall n \ge n_0\right\}

Ω\Omega-notation

Ω(g(n))={f(n)  c, n0>0, 0cg(n)f(n), nn0}\Omega(g(n)) = \left\{f(n)\ |\ \exist c,\ n_0 \gt 0,\ 0 \le cg(n) \le f(n),\ \forall n \ge n_0\right\}

Θ\Theta-notation

Θ(g(n))={f(n)  c1, c2, n0>0, 0c1g(n)f(n)c2g(n), nn0}\Theta(g(n)) = \left\{f(n)\ |\ \exist c_1,\ c_2,\ n_0 \gt 0,\ 0 \le c_1g(n) \le f(n) \le c_2g(n),\ \forall n \ge n_0\right\}

Tip: OO and oo
f(n)cg(n)f(n)<cg(n)f(n) \le cg(n) \rightarrow f(n) \lt cg(n)

Calculating

Typically, we do like this when calculating asymptotic running time:

e.g.  T(n)=An2+Bn+C=O(n2)T(n) = An^2 + Bn + C = O(n^2)

Question: Master Theorem