Foundation of Algorithm 知识笔记加习题总结

前言

这个笔记旨在于复习和准备算法分析的基本知识,使用的课程是NYU courant的foundation of Algorithm. 本笔记会根据老师的进度实时更新。

第一章 基本数学知识和渐进分析(Basic mathematical knowledge and asymptotic analysis)

渐进分析符号(asymptotic symbol)

1. O ( g ( n ) ) = { f ( n ) : ∃  constants  c , n 0 > 0  s.t.  ∀ n ≥ n 0 : f ( n ) ≤ c ⋅ g ( n ) } O(g(n))=\left\{f(n): \exists \text { constants } c, n_{0}>0 \text { s.t. } \forall n \geq n_{0}: f(n) \leq c \cdot g(n)\right\} O(g(n))={ f(n): constants c,n0>0 s.t. nn0:f(n)cg(n)}

O ( g ) O(g) O(g)表示的是函数f(n)的上界(或者说上限),而严格意义的上界则表示为 o ( g ) o(g) o(g)(任意常数c,都可以是的上面的表达式成立)
注:当两个函数增长率(growth rate)一样的时候,这两个函数可以互为上界

2. Ω ( g ( n ) ) = { f ( n ) : ∃ \Omega(g(n))=\left\{f(n): \exists\right. Ω(g(n))={ f(n): constants c , n 0 > 0 c, n_{0}>0 c,n0>0 s.t. ∀ n ≥ n 0 : f ( n ) ≥ c ⋅ g ( n ) } \left.\forall n \geq n_{0}: f(n) \geq c \cdot g(n)\right\} nn0:f(n)cg(n)}

Ω ( g ) \Omega(g) Ω(g)表示的是函数f(n)的下界(或者说下限),而严格意义上的下界则表示为 ω ( g ) \omega(g) ω(g)

3. Θ ( g ( n ) ) = { f ( n ) : ∃ \Theta(g(n))=\left\{f(n): \exists\right. Θ(g(n))={ f(n): constants c 1 , c 2 , n 0 > 0 c_{1}, c_{2}, n_{0}>0 c1,c2,n0>0
s.t. ∀ n ≥ n 0 : c 1 ⋅ g ( n ) ≤ f ( n ) ≤ c 2 ⋅ g ( n ) } \left.\forall n \geq n_{0}: c_{1} \cdot g(n) \leq f(n) \leq c_{2} \cdot g(n)\right\} nn0:c1g(n)f(n)c2g(n)}

Θ ( g ) \Theta(g) Θ(g)表示的是当上下限相等的时候的算法开销

4.当 f ( n ) = Θ ( g ) f(n)=\Theta(g) f(n)=Θ(g) g = Θ ( f ) g=\Theta(f) g=Θ(f),且此时上下界对应的是相同的

限制测试(limits test) 和增长率(growth rate)

lim ⁡ n → ∞ f ( n ) g ( n ) = c \lim _{n \rightarrow \infty} \frac{f(n)}{g(n)}=c nlimg(n)f(n)=c

  • If c = 0 c=0 c=0, then f = o ( g ) f=o(g) f=o(g)
  • If c = ∞ c=\infty c=, then f = ω ( g ) f=\omega(g) f=ω(g)
  • If 0 < c < ∞ 0<c<\infty 0<c<, i.e., a finite positive constant, then f = Θ ( g ) f=\Theta(g) f=Θ(g)

循环不变性(loop invariant)

这个方法的作用是是为了确保在一组在循环体内、每次迭代均保持为真的性质,通常被用来证明程序或伪码的正确性。具体可以分为三步(for example: bubble sort):

  1. Base case: When i=1,trivially true because empty array
  2. Maintenance: Assume that the inner loop iterates from n to i+1 and finds that smallest elements among it. And also that true before iteration i. Then A[i] contains the smallest elements from A[i,…,n], thanks to inner loop
  3. Terminates: Algorithm Terminates Trivially and at i=n-1. So A[1,…,n-1] is sorted and A[n] is the largest element, and therefore fully sorted.

数学知识小结

1. lim ⁡ h → ∞ n b a n = 0 ⇒ n b = 0 ( a n ) \lim _{h \rightarrow \infty} \frac{n^{b}}{a^{n}}=0 \quad \Rightarrow \quad n^{b}=0\left(a^{n}\right) limhannb=0nb=0(an)

2. 2 π n ( n e ) n ⩽ n ! ⩽ 2 π n ( n e ) n + 1 12 n \sqrt{2 \pi n}\left(\frac{n}{e}\right)^{n} \leqslant n ! \leqslant \sqrt{2 \pi n}\left(\frac{n}{e}\right)^{n+\frac{1}{12 n}} 2πn (en)nn!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使 LaTeX algorithm 中的 "Algorithm" 粗,可以使用 algorithm2e 宏包。首先,确保已经正确载了 algorithm2e 宏包。然后,在 \begin{algorithm} 之前添以下命令: \SetAlgoCaptionSeparator{.} \renewcommand{\algorithmcfname}{\textbf{Algorithm}} 这些命令会设置算法标题的分隔符和算法关键词的样式。接下来,在你的算法代码之前添以下命令: \textbf{Algorithm} \caption{Your caption}\label{alg:label} 这个命令会将 "Algorithm" 粗,并在标题前显示。在你的算法代码中,你可以继续使用 \State 和其他算法关键字来编写伪代码。 在你的算法代码结束之后,添以下命令: \end{algorithm} 这个命令会结束算法环境。 总结一下,要使 LaTeX algorithm 中的 "Algorithm" 粗,你需要: 1. algorithm2e 宏包 2. 在 \begin{algorithm} 之前添 \SetAlgoCaptionSeparator{.} 和 \renewcommand{\algorithmcfname}{\textbf{Algorithm}} 3. 在算法标题之前添 \textbf{Algorithm} \caption{Your caption}\label{alg:label} 4. 在算法代码之后添 \end{algorithm} 这样就可以使算法标题中的 "Algorithm" 粗了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Latex algorithm2e 算法伪代码 官方介绍文档.pdf](https://download.csdn.net/download/yyl424525/12045988)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Latex Algorithm 没有粗](https://blog.csdn.net/jh1513/article/details/129124385)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值