MSIS 655 Advanced Business Applications Programming Week 13 Searching and Sorting (cont.) In this chapter you will learn: To sort arrays using the recursive merge sort algorithm. To determine the efficiency of merge sort algorithms. 12/2/2018 13.1
Merge Sort Splits array into two approximately equal sized subarrays, sorts each subarray, then merges the subarrays The following implementation is recursive Base case is a one-element array which cannot be unsorted Recursion step splits an array into two pieces, sorts each piece, then merges the sorted pieces 12/2/2018
12/2/2018
12/2/2018
12/2/2018
12/2/2018
Efficiency of Merge Sort Far more efficient than selection sort or insertion sort Last merge requires n – 1 comparisons to merge entire array Each lower level has twice as many calls to method merge, with each call operating on an array half the size which results in O(n) total comparisons There will be O(log n) levels Results in O(n log n) 12/2/2018
Lab activities (Week 13) Exercise (pp. 816) 16.10 12/2/2018