Unleash Your Potential - Namagunga Girls Coding Club
Merge sort
1. Sorting Algorithms
Department of Computer Science
Islamia College University Peshawar
Fall 2012 Semester
BCS course: CS 00 Analysis of Algorithms
Course Instructor: Mr. Zahid
7. Recurrence Relation
Recall for Divide and Conquer algorithms
T(n) = aT(n/b) + D(n) + C(n)
Here a=2, and if we assume n is a power of 2, then each divide
step leads to sub-arrays of size n/2
D(n)=θ(1)
C(n)= θ(n)
T(n)=2T(n/2)+θ(n)
7
Lecture #5
Adapted from slides by Dr A. Sattar
Wednesday, March 4, 2009
9. Worst and Average-case Scenario
Worst case running time of merge sort is θ(nlgn)
Average case running time of merge sort is also θ(nlgn)
Best case?
9
Lecture #5
Adapted from slides by Dr A. Sattar
Wednesday, March 4, 2009
10. Worst and Average-case Scenario
Worst case running time of merge sort is θ(nlgn)
Average case running time of merge sort is also θ(nlgn)
Best case?
9
Lecture #5
Adapted from slides by Dr A. Sattar
Wednesday, March 4, 2009