
分而治之 是一种基于递归地将问题分解为多个相似类型的子问题,并且这些子问题可以很容易地解决的算法。
示例
让我们举一个例子来更深入地了解分而治之的技巧 -
function recursive(input x size n)
if(n < k)
Divide the input into m subproblems of size n/p.
and call f recursively of each sub problem
else
Solve x and returnCombine the results of all subproblems and return the solution to the original problem.
Explanation − In the above problem, the problem set is to be subdivided into smaller subproblems that can be solved easily.
Masters Theorem for divide and conquer is an analysis theorem that can be used to determine a big-0 value for recursive relation algorithms. It is used to find the time required by the algorithm and represent it in asymptotic notation form.
Example of runtime value of the problem in the above example −
T(n) = f(n) + m.T(n/p)
For most of the recursive algorithm, you will be able to find the Time complexity For the algorithm using the master's theorem, but there are some cases master's theorem may not be applicable. These are the cases in which the master's theorem is not applicable. When the problem T(n) is not monotone, for example, T(n) = sin n. Problem function f(n) is not a polynomial.
As the master theorem to find time complexity is not hot efficient in these cases, and advanced master theorem for recursive recurrence was designed. It is design to handle recurrence problem of the form −
BJXShop网上购物系统是一个高效、稳定、安全的电子商店销售平台,经过近三年市场的考验,在中国网购系统中属领先水平;完善的订单管理、销售统计系统;网站模版可DIY、亦可导入导出;会员、商品种类和价格均实现无限等级;管理员权限可细分;整合了多种在线支付接口;强有力搜索引擎支持... 程序更新:此版本是伴江行官方商业版程序,已经终止销售,现于免费给大家使用。比其以前的免费版功能增加了:1,整合了论坛
T(n) = aT(n/b) + ø((n^k)logpn)
其中 n 是问题的规模。
a = 递归中的子问题数量,a > 0
n/b = 每个子问题的规模 b > 1,k >= 0,p 是一个实数。
为了解决这种类型的问题,我们将使用以下解决方案:
- 如果 a > bk,那么 T(n) = ∅ (nlogba)
- 如果 a = bk,那么
- 如果 p > -1,那么 T(n) = ∅(nlogba logp+1n)
- 如果 p = -1,那么 T(n) = ∅(nlogba loglogn)
- 如果 p ba)
- 如果 a k,那么
- 如果 p > = 0,那么 T(n)= ∅(nklogpn)
- 如果 p
使用高级主算法,我们将计算一些算法的复杂度 −
二分查找 − t(n) = θ(logn)
归并排序 − T(n) = θ(nlogn)









