首页 > 后端开发 > C++ > 正文

高级主定理用于分治递归

王林
发布: 2023-08-31 21:09:17
转载
953人浏览过

高级主定理用于分治递归

分而治之 是一种基于递归地将问题分解为多个相似类型的子问题,并且这些子问题可以很容易地解决的算法。

示例

让我们举一个例子来更深入地了解分而治之的技巧 -

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 return
登录后复制

Combine 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 −

T(n) = aT(n/b) + &oslash;((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)

以上就是高级主定理用于分治递归的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号