

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















2
Overview
๏ฌ Divide and Conquer
๏ฌ Merge Sort
๏ฌ Quick Sort
4
Divide and Conquer - Sort
5
Divide and Conquer - Sort
sort the FirstPart sort the SecondPart
sort FirstPart sort SecondPart
7
Merge Sort: Idea
Merge
Recursively sort
Divide into two halves
FirstPart (^) SecondPart
FirstPart SecondPart
8
Merge Sort: Algorithm
Recursive Call
10
Temporary Arrays
Merge-Sort: Merge Example
11
Merge-Sort: Merge Example
i=0 (^) j=
k=
13
Merge-Sort: Merge Example
i=
k=
j=
14
Merge-Sort: Merge Example
i=2 j=
k=
16
Merge-Sort: Merge Example
i=2 (^) j=
k=
17
Merge-Sort: Merge Example
k=
i=2 (^) j=
19
Merge-Sort: Merge Example
i=4 j=
k=
20
Merge(A, left, middle, right)
**1. n 1 โ middle โ left + 1
Space: n Time : cn for some constant c