Click here to load reader

• date post

18-Dec-2015
• Category

## Documents

• view

214
• download

2

TAGS:

Embed Size (px)

### Transcript of CSE 1302 Lecture 22 Quick Sort and Merge Sort Richard Gesick

• Slide 1
• CSE 1302 Lecture 22 Quick Sort and Merge Sort Richard Gesick
• Slide 2
• Merge Sort Sorts an array by Cutting the array in half Recursively sorting each half Merging the sorted halves Dramatically faster than the selection sort
• Slide 3
• Merge Sort
• Slide 4
• The key part of the MergeSort public void sort() { if (a.length
• even more process (b) left pivot right 4 3 2 2 5 8 0 11 9 14 20 now the process will stop when the left arrow> right arrow since its not true yet, continue on pivot 4 3 2 2 5 8 0 11 9 14 20 left right the left arrow stops on 8(the pivot) because we are looking for values greater than or equal to the pivot and now we swap again
• Slide 21
• even more process (c) pivot 4 3 2 2 5 0 8 11 9 14 20 left right left arrow is still less than right so continue the process pivot 4 3 2 2 5 0 8 11 9 14 20 right left the first subdivision is now complete and the 2 sublists can now be sorted using the same function
• Slide 22
• key parts of the QuickSort public void quicksort( list_type list, int left, int right) { left_arrow=left; right_arrow=right; pivot=list[(left+right)/2]; //... the recursive calls if (left