# Sorting Chapter 4 Sorting Sorting is one of

- Slides: 22

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 – O(n 2) comparidons. • Heapsort – selection sort with right data structure • Insertion Sort – very little storage; optimal comparisons – O(n 2) data movement

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.

Quicksort

Quicksort

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

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.

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)

Vito’s Family

Vito’s Family

Vito’s Family

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.

Stacks of Flapjacks

Stacks of Flapjacks

Stacks of Flapjacks

Stacks of Flapjacks

Bridge

Bridge

Bridge

- Internal vs external sorting
- One empire one god one emperor
- Little dog run
- One king one law one faith
- Byzantine definition
- One ford behaviors
- See one do one teach one
- See one, do one, teach one
- Twelfth night speeches
- See one do one teach one
- One vision one identity one community
- Asean one vision one identity one community
- Sin entered through one man
- Figurative language in the song one thing by one direction
- Hundred tens ones
- Othello act one scene one summary
- One team one fight
- One goal one passion
- One gene one polypeptide
- Maybe this one moment with this one person
- One voice one look
- One future world
- One / ones grammar