1 / 14

Sorting Algorithms

Sorting Algorithms. Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University. About Sorting. We have covered Selection sort Insertion sort Bubble sort Heap sort Other efficient sorting algorithms Merge sort  O ( n log n ) in worse case

bfeliciano
Download Presentation

Sorting Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sorting Algorithms Jyh-Shing Roger Jang (張智星) CSIE Dept, National Taiwan University

  2. About Sorting • We have covered • Selection sort • Insertion sort • Bubble sort • Heap sort • Other efficient sorting algorithms • Merge sort  O(n log n) in worse case • Quick sort  O(n log n) in average case, O(n2) in worse case O(n2) in worse case O(n log n) in worse case

  3. TERMINOLOGIES FOR SORTING • In-place sorting • Sorting a sequence with O(1) extra space to store intermediate results • Stable sorting • If the same element is presented multiple time, then they remain the original relative order of positions after sorting • External sorting • Sorting records not stored in memory Quiz! Slow access! Locality important! Quiz! Important for Multiple-key sorting!

  4. C++ STL Sorting Functions • sort function template • void sort(iterator begin, iterator end) • void sort(iterator begin, iterator end, Comparator cmp) • begin and end are start and end marker of a container (or a range of it) • Container needs to support random access such as vector • sort() is not a stable sorting • stable_sort() is stable What methods are use here? Please post to FB!

  5. Animation for Sorting Keyvalue before execution during execution after execution N distinct keys within [1,N] Animation of sorting algorithms Index 45-degree line after sorting

  6. Insertion Sort

  7. Selection Sort

  8. Bubble Sort

  9. Merge Sort

  10. Quicksort

  11. Heap Sort: Heap Construction

  12. HeapSort: Sorting Phase

  13. Straight Radix Sort

  14. Shell Sort

More Related