0% found this document useful (0 votes)
16 views18 pages

L3 - Recurrence

Uploaded by

manju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

L3 - Recurrence

Uploaded by

manju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

RECURRENCE RELATION

ALGORITHM DESIGNING APPROACH


🞆 There are two approaches which can be used to
write algorithms:

🞆 Incremental (insertion sort)


🞆 Divide and Conquer (Merge sort, Quick sort)
RECURRENCE
🞆 For large value of input size, recursive
algorithms gives exponential running time
complexity.

🞆 When an algorithm contains a recursive call to


itself, then its running time can be described by
a recurrence equation or recurrence.

🞆 Following algorithms are recursive algorithms:


⚫ Fibonacci series calculation
⚫ Factorial calculation
⚫ Binary Search
⚫ Merge Sort
SOLVING RECURRENCES
🞆 Solving recurrences means the asymptotic evaluation of their
efficiency.

🞆 The recurrence can be solved using some mathematical tools


and then bounds (big-O, big-Ω, and big-Θ) on the
performance of the algorithm should be found according to
the corresponding criteria.
COMPOSING RECURRENCES FOR DIVIDE
AND CONQUER ALGORITHMS

🞆 A recurrence for the running time of a


divide-and-conquer algorithm is based
on the three steps:

🞆 1) Let T(n) be the running time of a


problem of size n. If the problem size is
small enough (n≤c) for some constant
c, the straightforward solution takes
constant time, which we write as Θ(1)
COMPOSING RECURRENCES
🞆 2) Suppose that our division of the
problem yields a subproblems, each of
which is 1/b size of the original.

🞆 3) If we take D(n) time to divide the


problem into subproblems and C(n)
time to combine the solutions to the
subproblems to the original problem,
we got the recurrence
SOLVING RECURRENCES
🞆 Hence, solving recurrences means
finding the asymtotic bounds (big-O,
big-Ω, and big-Θ) for the
function T(n).
SOLVING RECURRENCES

🞆 Recursion-tree method converts


recursion into a tree whose nodes
represent the “subproblems” and their
costs.
🞆 Substitution method – we guess a
bound and then use mathematical
induction to prove our guess.
🞆 Master method provides bounds for
recurrences of the form :
RECURSION TREE METHOD

🞆 A recursion tree is used to present a


problem as a composition of
subproblems. It is very suitable to
present any divide-and-conquer
algorithm.

🞆 Each node represents the cost of a


single subproblem.

🞆 Usually each level of the tree


corresponds to one step of the
RECURSION TREE

🞆 We sum the costs within each level of the


tree to obtain a set of per-level costs.

🞆 Then we sum all the per-level costs to


determine the total cost of all levels of
the recursion.

🞆 As a result, we generate a guess that can


be then proven either by substitution
method or by master theorem
method.
SOLVING RECURRENCES : THE MASTER THEOREM

🞆 Given: a divide and conquer algorithm


⚫ An algorithm that divides the problem of
size n into a subproblems, each of size n/b.

⚫ Let the cost of each stage (i.e., the work to


divide the problem + combine solved
subproblems) be described by the function
f(n).

🞆 Then, the Master Theorem gives us a some


rules for the algorithm’s running time:
SOLVING RECURRENCES :THE MASTER METHOD

🞆 Provides the immediate solution for recurrences


of the form

🞆 f(n) is a given function, which satisfies some


pre-determined conditions.
THE MASTER THEOREM

🞆 if T(n) = aT(n/b) + f(n) then


EXAMPLE : USING THE MASTER
METHOD

🞆 T(n) = 9T(n/3) + n
⚫a=9, b=3, f(n) = n
nlog a = nlog 9 = n2
b 3

Since f(n) = n= O(nlog 3 9-ε


), where ε =1,case 1 applies:

Thus the solution is T(n) =


Θ(n2)
USING THE MASTER METHOD

🞆 T(n) = 2T(n/2) + n
USING THE MASTER METHOD

🞆 T(n) = 2T(n/2) + n

You might also like