1 / 12

Design and Analysis of Algorithms Recurrences

Design and Analysis of Algorithms Recurrences. Haidong Xue Summer 2012, at GSU. What is a recurrence?. “an equation or inequality that describes a function in terms of its value on smaller inputs” Time complexity of divide and conquer algorithms can be represented as recurrence equations.

azizi
Télécharger la présentation

Design and Analysis of Algorithms Recurrences

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design and Analysis of AlgorithmsRecurrences HaidongXue Summer 2012, at GSU

  2. What is a recurrence? • “an equation or inequality that describes a function in terms of its value on smaller inputs” • Time complexity of divide and conquer algorithms can be represented as recurrence equations. • What is the recurrence of fact2 • fact2(n) • if(n<=1) return 1; • return n*fact2(n-1);

  3. How to solve recurrences? • What can be omitted? • Floor, ceiling and boundary conditions • Since the solution typically doesn’t change by more than a constant factor • Example: merge sort

  4. How to solve recurrence? • Three methods to solve recurrence • Substitution method • Recursion-tree method • Master method

  5. Substitution method-examples • Guess the solution • Use mathematical induction to prove it

  6. Substitution method-examples Guess: • Basis • When n=2, • Inductive steps • Inductive hypothesis: when n<=k, k>=2, • The statement needs to be proved: when n=k+1,

  7. Substitution method-examples Proof: • When n=k+1, • Since , • So, =O((k+1)lg(k+1)),

  8. Substitution method-examples • It could be very hard prove even if one made the right guess • 4.3-2 • How to make a guess? • Recursion-tree

  9. Recursion-tree • Recursion tree: each node represents the known cost of a sub problem • Help us to make a guess of the total cost

  10. Recursion-tree = = …… …… = Totally?

  11. The master theorem Let a>=1 and b>1 be constants, let f(n) be a function, and let T(n) be defined on the nonnegative integers by the recurrence: • If for some constant>0, then • If , then • If for some constant>0, and if for some constant c<1 and all sufficiently large n, then

  12. The master theorem Θ() Θ(lg(n)) (cannot use master method) Θ()

More Related