组合算法 本文最后更新于:2021年10月4日 晚上 『组合数学』5 组合算法 分治策略 最好情况:令N=2nN = 2^nN=2n情形 Tn=2Tn−1+2n−1T_n = 2T_{n-1}+2^{n-1}Tn=2Tn−1+2n−1 G(x)=∑i=0nTixi=1(1−2x)2=∑i=0nn2n−1xn⇒Tn=n2n−1=12Nlog2NG(x) = \sum_{i=0}^nT_ix^i = \frac{1}{(1-2x)^2} \\ \qquad = \sum_{i=0}^n n2^{n-1}x^n \Rightarrow T_n = n2^{n-1} = \frac 12 N\log_2^N G(x)=i=0∑nTixi=(1−2x)21=i=0∑nn2n−1xn⇒Tn=n2n−1=21Nlog2N 最坏情况的复杂性分析 Cn=2Cn−1+2n−1C_n = 2C_{n-1} +2^n-1Cn=2Cn−1+2n−1 则其母函数为 G(x)=∑i=1nCixi=1(1−2x)2+2x(1−2x)2+11−x−11−2xG(x) = \sum_{i=1}^nC_ix^i \\ \qquad =\frac{1}{(1-2x)^2} + \frac{2x}{(1-2x)^2}+ \frac 1 {1-x} -\frac 1{1-2x}G(x)=i=1∑nCixi=(1−2x)21+(1−2x)22x+1−x1−1−2x1 展开分解得: 取xnx^nxn的系数=Cn=(n+n−1−1)2n−1=(n−1)2n−1=Nlog2N−N+1=O(nlogn)= C_n = (n+n-1-1)2^{n-1} \\= (n-1)2^n -1 = N\log_2^N -N+1 = O(nlogn)=Cn=(n+n−1−1)2n−1=(n−1)2n−1=Nlog2N−N+1=O(nlogn) 快速排序 最好与最坏情况类似, 平均情况 以等概率分布Tn=n−1+1n∑k=1n(Tk+Tn−k)=2n∑k=0n−1Tk+n−1T_n = n-1+\frac 1n\sum\limits_{k=1}^n(T_k+T_{n-k}) = \frac 2n\sum\limits_{k=0}^{n-1}T_k+n-1Tn=n−1+n1k=1∑n(Tk+Tn−k)=n2k=0∑n−1Tk+n−1 于是有 Tn+1=n+2n+1∑k=0nTk⇒(n+1)Tn+1−nTn=n+2Tn⇒Tn+1n+2−Tnn+1=2n(n+1)(n+2)⇒Zn+1−Zn=4n+2−2n+1⇒Tn=(n+1)Zn=(n+1)(2∑k=2n−11k+1+4n+1−2)<(n+1)(2lnn−2(n+1)ln2+2)∈O(nlogn)T_{n+1} = n+\frac 2{n+1}\sum\limits_{k=0}^nT_k \\\Rightarrow (n+1)T_{n+1}-nT_n = n +2T_n\\\Rightarrow\frac {T_{n+1}}{n+2} - {\frac{T_n}{n+1}} = \frac{2n}{(n+1)(n+2)} \\ \Rightarrow Z_{n+1}-Z_n = \frac{4}{n+2}-\frac 2{n+1} \\ \Rightarrow T_n =(n+1)Z_n = (n+1)(2\sum\limits_{k=2}^{n-1}\frac 1{k+1}+\frac 4{n+1}-2)\\<(n+1)(2\ln n -2(n+1)ln2 +2)\in O(n\log n)Tn+1=n+n+12k=0∑nTk⇒(n+1)Tn+1−nTn=n+2Tn⇒n+2Tn+1−n+1Tn=(n+1)(n+2)2n⇒Zn+1−Zn=n+24−n+12⇒Tn=(n+1)Zn=(n+1)(2k=2∑n−1k+11+n+14−2)<(n+1)(2lnn−2(n+1)ln2+2)∈O(nlogn) [ ] 若数据以泊松分布而非等概率求其平均情况 ClassNote #组合数学 #Math 组合算法 http://example.com/2021/05/30/Combinatorial Mathematics/CM-组合算法/ 作者 BFlame 发布于 2021年5月30日 许可协议 机器学习基础知识 上一篇 排列与组合 下一篇 Please enable JavaScript to view the comments