Sorting Algorithms
Department of Computer Science
Islamia College University Peshawar

Fall 2012 Semester
BCS course: CS 0...
MergeSort - Illustration

2

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
MergeSort – Illustration (contd…)

3

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
MergeSort – Illustration (contd…)

4

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Pseudo code

5

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Pseudo code

6

Lecture #5

Wednesday, March 4, 2009
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...
Worst-case scenario

8

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Worst and Average-case Scenario
 Worst case running time of merge sort is θ(nlgn)
 Average case running time of merge so...
Worst and Average-case Scenario
 Worst case running time of merge sort is θ(nlgn)
 Average case running time of merge so...
Upcoming SlideShare
Loading in …5
×

Merge sort

613 views

Published on

Published in: Technology, Education
  • Be the first to comment

Merge sort

  1. 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
  2. 2. MergeSort - Illustration 2 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  3. 3. MergeSort – Illustration (contd…) 3 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  4. 4. MergeSort – Illustration (contd…) 4 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  5. 5. Pseudo code 5 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  6. 6. Pseudo code 6 Lecture #5 Wednesday, March 4, 2009
  7. 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
  8. 8. Worst-case scenario 8 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  9. 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. 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

×