Upcoming SlideShare
Loading in...5
×

Like this presentation? Why not share!

# Merge sort

## on Dec 30, 2013

• 225 views

### Views

Total Views
225
Views on SlideShare
225
Embed Views
0

Likes
0
Downloads
1
Comments
0

No embeds

### Upload Details

Uploaded via as Microsoft PowerPoint

### Usage Rights

© All Rights Reserved

### Report content

• Comment goes here.
Are you sure you want to
Your message goes here
Edit your comment

## Merge sortPresentation Transcript

• Sorting Algorithms Department of Computer Science Islamia College University Peshawar Fall 2012 Semester BCS course: CS 00 Analysis of Algorithms Course Instructor: Mr. Zahid
• 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 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
• 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 sort is also θ(nlgn)  Best case? 9 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 sort is also θ(nlgn)  Best case? 9 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009