








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the divide-and-conquer algorithm strategy, its technique, and examples of its application in sorting algorithms such as mergesort and quicksort. The document also includes the master theorem and its application to the analysis of divide-and-conquer algorithms.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









General Divide-and-Conquer Recurrence
General Divide-and-Conquer Recurrence
n
n ) =
aT
aT (
n/b
n/b ) +
f
f (
n
n )
where
where f
f (
n
n )
n
n
d
d
d
d
Master Theorem
Master Theorem : If
: If a < b
a < b
d
d
n
n )
n
n
d
d
If
If a = b
a = b
dd
n
n )
n
n
dd
log
log n
n )
If
If a > b
a > b
dd
n
n )
n
n
log
log
b
b
a
a
Note: The same results hold with O instead of
Note: The same results hold with O instead of
Examples:
Examples: T
n
n
) = 4
n
n
/2) +
n
n
n
n
)
n
n ) = 4
n
n /2) +
n
n
2
2
n
n )
n
n ) = 4
n
n /2) +
n
n
33
n
n )
n^
n^ )
n^2log n
n^2log n )
n^
n^ )
Time complexity: Θ
p+q
p+q )
n
n )
) comparisons
close to theoretical minimum for comparison-
based sorting:
log
2
n ! ≈ n log
2
n - 1.44 n
(bottom-up)
T(n) = 2T(n/2) +
T(n) = 2T(n/2) + Θ
(n), T(1) = 0
(n), T(1) = 0
p
A[ i ] p
A[ i ] p
5 3 1 9 8 2 4 7
2
better pivot selection: median of three partitioning
These combine to 20-25% improvement