1 / 22

Sorting

Sorting. Chapter 4. Sorting. Sorting is one of the most fundamental problem in computer science. It is a useful preprocessing to make short work of other problems. Applications of Sorting. Applications of Sorting. Sorting Algorithms. Selection Sort very little storage; data movement

vgrover
Download Presentation

Sorting

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 Chapter 4

  2. Sorting • Sorting is one of the most fundamental problem in computer science. • It is a useful preprocessing to make short work of other problems.

  3. Applications of Sorting

  4. Applications of Sorting

  5. Sorting Algorithms • Selection Sort • very little storage; data movement • O(n2) comparidons. • Heapsort • selection sort with right data structure • Insertion Sort • very little storage; optimal comparisons • O(n2) data movement

  6. Sorting agorithms • Quicksort • This algorithm reduces the job of sorting one big array into the job of sorting two smaller arrays by performing a partition step. • The partition separates the array into those elements that are less than the pivot/divider element, and • those which are strictly greater than this pivot/divider element.

  7. Quicksort

  8. Quicksort

  9. Multicriteria Sorting • How can we break ties in sorting using multiple criteria?

  10. Stable Sorting • Identical keys are kept in the same relative order they were in before the sorting. • we could sort by the first name, • then do stable sort by the last name • We know that the final results are sorted by both major and minor keys.

  11. Library Routines • C • stdlib.h contains library functions • qsort • C++ • C++STL • sort • stable_sort • Java • java.util.Arrays • sort(Object[] a) • sort(Object[] a, Comparator c)

  12. Vito’s Family

  13. Vito’s Family

  14. Vito’s Family

  15. Vito’s Family • What is the right version of average to solve Vito’s problem: mean, median, or something else? • mean is easy to compute • median: the middle element in the sorted list. • This can be determined easily after sorting the items. • This element can be determined without sorting the elements using a quicksort like algorithm called quickselect.

  16. Stacks of Flapjacks

  17. Stacks of Flapjacks

  18. Stacks of Flapjacks

  19. Stacks of Flapjacks

  20. Bridge

  21. Bridge

  22. Bridge

More Related