Presentation is loading. Please wait.

Presentation is loading. Please wait.

MSIS 655 Advanced Business Applications Programming

Similar presentations


Presentation on theme: "MSIS 655 Advanced Business Applications Programming"— Presentation transcript:

1 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

2 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

3 12/2/2018

4 12/2/2018

5 12/2/2018

6 12/2/2018

7 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

8 Lab activities (Week 13) Exercise (pp. 816) 16.10 12/2/2018


Download ppt "MSIS 655 Advanced Business Applications Programming"

Similar presentations


Ads by Google