



















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 in-depth look at the merge sort algorithm, including its analysis, recurrences, and solving techniques using the master theorem and the substitution method. It also includes examples and explanations of asymptotic notation and the iteration method.
Typology: Slides
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















and n 0 such that f(n) ≤ c ⋅ g(n) for all n ≥ n (^0)
and n 0 such that f(n) ≤ c ⋅ g(n) ∀ n ≥ n 0
that 0 ≤ c⋅g(n) ≤ f(n) ∀ n ≥ n 0
such that c 1 g(n) ≤ f(n) ≤ c 2 g(n) ∀ n ≥ n 0
f(n) = O(g(n)) AND f(n) = Ω(g(n))
MergeSort(A, left, right) {
if (left < right) { mid = floor((left + right) / 2); MergeSort(A, left, mid); MergeSort(A, mid+1, right); Merge(A, left, mid, right); }
}
// Merge() takes two sorted subarrays of A and
// merges them into a single sorted subarray of A
// (how long should this take?)
A = {10, 5, 7, 6, 1, 4, 8, 3, 2, 9};
in terms of its value on smaller functions
cn n
n T
c n
T n
n
n
c s n
s n
n s n n
n s n
c n
n T
c n
T n
cn n b
n aT
c n
T n
to find the constants and show that solution works
to find the constants and show that solution works
c s n n
n s n
c s n n
n s n
c s n n
n s n
n s n n
n s n
= n + s(n-1)
= n + n-1 + s(n-2)
= n + n-1 + n-2 + s(n-3)
= n + n-1 + n-2 + n-3 + s(n-4)
= …
= n + n-1 + n-2 + n-3 + … + n-(k-1) + s(n-k)