Merge sort
Upcoming SlideShare
Loading in...5
×
 

Merge sort

on

  • 225 views

 

Statistics

Views

Total Views
225
Views on SlideShare
225
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Merge sort Merge sort Presentation 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