This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: divide this into two sets >>mergeSort(3,8,15,19) and mergeSort(23,6,1,10) divide again >>mergeSort(3,8), mergeSort(15,19), mergeSort(23,6), mergeSort(1,10) divide again ...ms(3), ms(8),. ..... put two together s=(3,8) s=(15,19) s=(6,23) s=(1,10) again s=(3,8,15,19) s=(1,6,10,23) again s=(1,3,6,8,10,15,19,23) How long does merge sort take? To find this out, we use sth called amortized time, that is we find first the time spent in one element in the array and then multiply this by n (the number of elements) Instructions done for one element:-copy operations: the # of comparisons is also the # of times an element-comparison:nlog(n) is copied to the new array, in the merge step If there are n elements, the time will be O(nlog(n))...
View Full Document