Advanced Algorithm 听课笔记(Introduction & Complexity Class)
Posted 糖果天王
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Advanced Algorithm 听课笔记(Introduction & Complexity Class)相关的知识,希望对你有一定的参考价值。
0x00 前言
作为学术生涯的最后一门课,选了一门据说是最难的,上下来的感觉也确实是难得不行,不太懂……
决定照着ppt和上课的笔记整理一下,以此争取达到复习的目的。
(意思是有些虽然写出来了,但自己都不见得明白,有的部分存疑后续去询问之后再做修改)
Introduction of Randomized Algorithm
0x01 Big O notation
-
f
(
n
)
=
O
(
g
(
n
)
)
:
≤
f(n)=O(g(n)):~ \\le
f(n)=O(g(n)): ≤
- which means ∃ c , l i m ‾ n → ∞ f ( n ) g ( n ) ≤ c \\exists~c, \\overlinelim_n \\rightarrow \\infty\\fracf(n)g(n)\\le c ∃ c,limn→∞g(n)f(n)≤c, c is constant
-
f
(
n
)
=
o
(
g
(
n
)
)
:
<
f(n)=o(g(n)):~ \\lt
f(n)=o(g(n)): <
- which means l i m ‾ n → ∞ f ( n ) g ( n ) = 0 \\overlinelim_n \\rightarrow \\infty\\fracf(n)g(n) = 0 limn→∞g(n)f(n)=0
-
f
(
n
)
=
Ω
(
g
(
n
)
)
:
≥
f(n)=\\Omega(g(n)):~ \\ge
f(n)=Ω(g(n)): ≥
- which means g ( n ) = O ( f ( n ) ) g(n)=O(f(n)) g(n)=O(f(n))
-
f
(
n
)
=
ω
(
g
(
n
)
)
:
>
f(n)=\\omega(g(n)):~ \\gt
f(n)=ω(g(n)): >
- which means g ( n ) = o ( f ( n ) ) g(n)=o(f(n)) g(n)=o(f(n))
-
f
(
n
)
=
Θ
(
g
(
n
)
)
:
=
f(n)=\\Theta(g(n)):~ =
f(n)=Θ(g(n)): =
- which means f ( n ) = O ( g ( n ) ) f(n)=O(g(n)) f(n)=O(g(n)) and f ( n ) = Ω ( g ( n ) ) f(n)=\\Omega(g(n)) f(n)=Ω(g(n))
0x02 QuickSort
Sorting Problem: Given a set S of n numbers, sort them into ascending order.
- Find random y y y of set S S S; (O(1))
- Partition S ∖ y S \\setminus \\y\\ S∖y into two sets S 1 S_1 S1 and S 2 S_2 S2; (n)
- Recursively sort S 1 S_1 S1 and S 2 S_2 S2
- Time complexity:
O
(
n
l
o
g
n
)
O(n log n)
O(nlogn) does not depend on input. It holds for every input.
E ( T ( n ) ) = 1 n ∑ k = 1 n ( E ( T ( n ) ) ∣ X n = k ) = 1 n ∑ k = 1 n ( E ( T ( k − 1 ) ) + E ( T ( n − k ) ) + n − 1 ∣ X n = k ) = 1 n ∑ k = 1 n ( E ( T ( k − 1 ) ) + E ( T ( n − k ) ) + n − 1 ) ∴ E ( T ( n ) ) = 1 n ∑ k = 1 n ( E ( T ( k − 1 ) ) + E ( T ( n − k ) ) + ( n − 1 ) ) \\beginaligned E(T(n))~&=\\frac1n\\sum_k=1^n\\left( E(T(n)) ~|~ X_n=k \\right) \\\\ &=\\frac1n\\sum_k=1^n\\left( E(T(k-1)) + E(T(n-k)) + n-1 ~|~ X_n=k \\right) \\\\ &=\\frac1n\\sum_k=1^n\\left( E(T(k-1)) + E(T(n-k)) + n-1 \\right) \\\\ \\therefore E(T(n))~&=\\frac1n\\sum_k=1^n\\left( E(T(k-1)) + E(T(n-k)) + (n-1) \\right) \\\\ \\endaligned E(T(n)) ∴E(T(n)) =n1k=1∑n(E(T(n)) ∣ Xn=k)=n1k=1∑n(E(T(k−1))+E(T(n−k))+n−1 ∣ Xn=k)=n1k=1∑n(E(T(k−1))+E(T(n−k))+n−1)=n1k=1∑n(E(T(k−1))+E(T(n−k))+(n−1))
0x03 Comparison Probability
判断序列中的两个数在QuickSort中被比较过的概率
当第
i
i
i个数字和第
j
j
j个数字曾经被比较过,设
X
i
j
=
1
X_ij=1
Xij=1,反之为0。 以上是关于Advanced Algorithm 听课笔记(Introduction & Complexity Class)的主要内容,如果未能解决你的问题,请参考以下文章 deeplearning.ai 神经网络和深度学习 week3 听课笔记 deeplearning.ai 神经网络和深度学习 week4 听课笔记 NTU课程笔记:MAS 714 algorithm and theory of computing:introduction
有
E
(
X
i
j
)
=
P
i
j
E(X_ij)= P_ij
E(Xij)=Pij,从而有
T
(
n
)
=
∑
1
≤
i
<
j
≤
n
X
i
j
T(n)= \\sum_1\\le i<j\\le n X_ij
T(n)=∑1≤i<j≤nXij<