Professional Documents
Culture Documents
Unsorted
Sorted 66
12 108
14 56
34 14
56 89
66 12
89 108
34
Divide
Merge Divide
Merge
66
14 108
56 56
66 108
14 89
12 12
34 34
89
Divide
Merge Divide
Merge Divide
Merge Divide
BCase
Merge
66 108 56
14 14
56 89
12 12
89 34
66 108
Divide
BCase
Merge Divide
BCase
Merge Divide
BCase
Merge Divide
BCase
Merge
56 89 12
66 108 Instructor: Najma Rasool
14 10
Merge Sort Analysis
suppose the running time (the number of operations) of
merge sort is a function of the number of elements to sort
– let the function be T(n)
merge sort works by splitting the list into two sub-lists
(each about half the size of the original list) and sorting the
sub-lists
– this takes T(n/2)+T(n/2)= 2T(n/2) running time
then the sub-lists are merged
– this takes O(n-1) running time
– T(n)=T[n/2]+T[n/2]+n-1
66 108 56 14 89 12 34
66 108 56 14 89 12 34
66 108 56 14 89 12 34