主定理

来自testwiki
跳转到导航 跳转到搜索

Template:NoteTA演算法分析中,主定理Template:Lang-en)提供了用渐近符号(大O符号)表示许多由分治法得到的递推关系式的方法。这种方法最初由喬恩·本特利Template:LeTemplate:Le在1980年提出,在那里被描述为解决这种递推的“天下無敵法”(Master method)。此方法经由经典演算法教科书Template:LeTemplate:Le羅納德·李維斯特Template:Le的《算法导论》推广而为人熟知。

不过,并非所有递推关系式都可应用支配理论。该定理的推广形式包括Template:Le

支配理论

假设有递归关系式

T(n)=aT(nb)+f(n),其中 a1b>1

其中,n为问题规模,a为递归的子问题数量,nb为每个子问题的规模(假设每个子问题的规模基本一样),f(n)为递归以外进行的计算工作。

情形一

如果存在常数ϵ>0,有

f(n)=O(nlogb(a)ϵ)(可不嚴謹的視作多项式地小于)

T(n)=Θ(nlogba)

情形二

如果存在常数ϵ0,有

f(n)=Θ(nlogbalogϵn)

T(n)=Θ(nlogbalogϵ+1n)

情形三

如果存在常数ϵ>0,有

f(n)=Ω(nlogb(a)+ϵ)(多项式地大于)

同时存在常数c<1以及充分大的n,满足

af(nb)cf(n)

T(n)=Θ(f(n))

常用演算法中的应用

演算法 递回关系式 运算时间 备注
二分搜尋演算法 T(n)=T(n2)+Θ(1) Θ(logn) 情形二(ϵ=0
二叉树遍历 T(n)=2T(n2)+Θ(1) Θ(n) 情形一
最佳排序矩阵搜索(已排好序的二维矩阵) T(n)=2T(n2)+O(logn) Θ(n)
合併排序 T(n)=2T(n2)+Θ(n) Θ(nlogn) 情形二(ϵ=0

参考文献

  • Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Sections 4.3 (The master method) and 4.4 (Proof of the master theorem), pp. 73–90.
  • Michael T. Goodrich and Roberto Tamassia. Algorithm Design: Foundation, Analysis, and Internet Examples. Wiley, 2002. ISBN 0-471-38365-1. The master theorem (including the version of Case 2 included here, which is stronger than the one from CLRS) is on pp. 268–270.