首頁  >  文章  >  後端開發  >  高級主定理用於分治遞歸

高級主定理用於分治遞歸

王林
王林轉載
2023-08-31 21:09:17916瀏覽

高級主定理用於分治遞歸

分而治之 是一種基於遞歸地將問題分解為多個相似類型的子問題,並且這些子問題可以輕鬆解決的演算法。

範例

讓我們舉一個例子來更深入地了解分而治之的技巧-

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#ideide 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 repymptotic notation form. 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 orare some cases master's theorem, but there not some cases master's theorem, not there not some cases not's theorem, not there not some cases not's theorem, not there not some cases not's theorem. 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 −##rreee#是問題的規模。

a = 遞迴中的子問題數,a > 0

n/b = 每個子問題的規模 b > 1,k >= 0,p 是實數。

為了解決這種類型的問題,我們將使用以下解決方案:

如果a > b

k

,那麼T(n) = ∅ ( nlogba)

    如果a = b
  • k,那麼
  • 如果p > -1,那麼T(n) = ∅(nlogba log
  • p 1n)
      如果p = -1,那麼T(n) = ∅(nlog
    • ba loglogn)
    • 如果p ba)
  • 如果a k
  • ,那麼
如果p > = 0 ,那麼T(n)= ∅(n
  • klogp
      n)
    • 如果p
    • 使用高階主演算法,我們將計算一些演算法的複雜度−
  • 二分查找 − t(n) = θ( logn)

    歸併排序 − T(n) = θ(nlogn)

    以上是高級主定理用於分治遞歸的詳細內容。更多資訊請關注PHP中文網其他相關文章!

    陳述:
    本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除