The document discusses divide and conquer algorithms and their analysis. It explains that divide and conquer algorithms follow three steps: (1) divide the problem into subproblems, (2) conquer the subproblems by solving them recursively, and (3) combine the solutions to solve the original problem. Many classical algorithms like merge sort and quicksort use the divide and conquer approach. The document also presents the master theorem for analyzing divide and conquer recurrences of the form T(n) = aT(n/b) + f(n). It demonstrates applying the master theorem to different examples to determine their time complexities.
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Recursive Algorithms Divide and Conquer Approach
1. UCSE010 - DESIGN AND ANALYSIS OF ALGORITHMS
1
Dr.Nisha Soms/SRIT
Semester-06/2020-2021
2. Many useful algorithms are recursive in
nature.
To solve a given problem, they call themselves
recursively one or more times.
These algorithms typically follow a divide &
Conquer approach.
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 2
3. Step 1:
Divide the given big problem into a number of sub-problems that are
similar to the original problem but smaller in size. A sub-problem may
be further divided into its sub-problems. A Boundary stage reaches
when either a direct solution of a sub-problem at some stage is
available or it is not further sub-divided. When no further sub-division
is possible, we have a direct solution for the sub-problem.
Step 2:
Conquer (Solve) each solutions of each sub-problem (independently)
by recursive calls; and then
Step 3:
Combine the solutions of each sub-problems to generate the solutions
of original problem.
3
Dr.Nisha Soms/SRIT
5. Any algorithms which follow the divide-and-conquer
strategy have the following recurrence form:
5
Dr.Nisha Soms/SRIT
6. Where
T(n) = running time of a problem of size n
a means “In how many part the problem is divided”
aT(n/b) means “Time required to solve a sub-problem each of size (n/b)”
If the problem size is small enough (say, n ≤ c for some constant c), we have
a base case. The brute-force (or direct) solution takes constant time: Θ(1)
D(n) is the cost(or time) of dividing the problem of size n.
C(n) is the cost (or time) to combine the sub-solutions.
6
Dr.Nisha Soms/SRIT
8. An analysis theorem that can be used to solve the time
complexity of recurrence relations of the form:
T(n) = aT(n/b) + f(n)
If a ≥ 1 and b > 1 are constants and f(n) is an
asymptotically positive function, then the Time
complexity of a recursive relation T(n) has the
following asymptotic bounds:
Case 1: If f(n) = O(nlog
b
a-ϵ), then T(n) = Θ(nlog
b
a).
Case 2: If f(n) = Θ(nlog
b
a), then T(n) = Θ(nlog
b
a * log n).
Case 3: If f(n) = Ω(nlog
b
a+ϵ), then T(n) = Θ(f(n)).
Where ϵ > 0 is a constant.
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 8
9. Consider T(n) = 4T(n/2) + n
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 9
•The given recurrence equation is of the form T(n) = a T(n/b) + f(n), Hence
Master theorem can be applied to perform analysis.
•Here, a = 4, b = 2, and f(n) = n respectively.
•Next, We calculate nlog
b
a from the given recurrence which is nlog
2
4 , that is n2
•The f(n) = n of the given recurrence is less when compared with the calculated
n2
•Hence, we apply Case 1: If f(n) = O(nlog
b
a-ϵ), then T(n) = Θ(nlog
b
a).
• f(n) = n = O(n2−ϵ) for, say, ϵ = 0.5. Thus, T(n) = Θ(nlog
b
a) = Θ(n2)
10. Consider T(n) = 4T(n/2) + n2
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 10
•The given recurrence equation is of the form T(n) = a T(n/b) + f(n), Hence
Master theorem can be applied to perform analysis.
•Here, a = 4, b = 2, and f(n) = n2 respectively.
•Next, We calculate nlog
b
a from the given recurrence which is nlog
2
4 , that is n2
•The f(n) = n2 of the given recurrence is same compared to the calculated n2
•Hence, we apply Case 2: If f(n) = Θ(nlog
b
a), then T(n) = Θ(nlog
b
a log n).
• f(n) = n2 = Θ(n2). Thus, T(n) = Θ(nlog
b
a log n) = Θ(n2 log n)
11. Consider T(n) = 4T(n/2) + n3
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 11
•The given recurrence equation is of the form T(n) = a T(n/b) + f(n), Hence
Master theorem can be applied to perform analysis.
•Here, a = 4, b = 2, and f(n) = n3 respectively.
•Next, We calculate nlog
b
a from the given recurrence which is nlog
2
4 , that is n2
•The f(n) = n3 of the given recurrence is larger compared to the calculated n2
•Hence, we apply Case 3: If f(n) = Ω(nlog
b
a+ϵ ), then T(n) = Θ(f(n)).
• f(n) = n3 = Ω(n2+ϵ) for, say, ϵ = 0.5. Thus, T(n) = Θ(f(n)) = Θ(n3).
12. https://medium.com/codex/divide-and-conquer-
algorithm-f766640ef038
Introduction to the Design and Analysis of Algorithms
(3rd ed.), Anany Levitin
https://www.cse.iitd.ac.in/~mausam/courses/col106/aut
umn2017/lectures/02-asymptotic.pdf
https://www.coursehero.com/file/51912947/L01-
Introppt/
https://anh.cs.luc.edu › notes
https://web.cs.ucdavis.edu/~gusfield/cs222f07/masterm
ethod.pdf
Semester-06/2020-2021 Dr.Nisha Soms/SRIT 12