Sorting
Last updated
Was this helpful?
Last updated
Was this helpful?
Many of programs we see today have something to do with sorting, that given an unsorted, randomly distributed array or list, research the best approach to sort in accordance to a specified alphabetical or numerical order.
Key concepts are introduced in this chapter such as .
is a binary relation on a set of elements that satisfies:
Antisymmetry: if a ⩾ b and b ⩾ a, then a = b
Transitivity: if a ⩽ b and b ⩽ c, then a ⩽ c
Totality: either a ⩽ b or b ⩽ a or both
A sorting algorithm is an adaptive sort scheme if it takes advantage of existing order of an original inputs. The presortedness of the input sequence benefits the sorting algorithm to achieve better running time.
Sorting algorithms that sort a list of elements base only on the comparisons of pairs without knowing other aspects of elements is comparison-based sort.
Note: assumes no preliminary knowledge about input arrays and thus the "general-purpose sorting method"; if not, some could be highly useful.
Proof: given a randomly distributed array of length n, assume the maximal compares required to sort the entire array is k and there is at least n! permutations to sort (each permutation is possible to yield the correct outcome); In each comparison, we obtain either a True or False that the element is displaced in the right location, then:
Sorting scheme that only a constant number of elements or memory spaces are required to store outside the original array is In-place Sort.
In-place Sort only requires Ο(1) extra space to sort the array. It usually sorts on the original array thus an useful approach to minimize the memory usage while sorting.
Formal Def: every has the running time of Ω(n ⋅ log n).
2k ⩾ n!, by , 2k ⩾ (n/2)n/2, k ⩾ (n/2) ⋅ log (n/2)
According to , noting that k ⩾ cn ⋅ log (cn), Τ(n) = Ω(n ⋅ log n)
Stable sorting algorithm maintains the relative order of elements with same value. Mathematically, given two records ℛ and 𝒬 with same value, ℛ precedes 𝒬 in the original array, then a will produce a sorted array with ℛ comes before 𝒬.
- a naive swapping-based sorting algorithm.
- an improved swapping-based sorting technique.
- mostly used approach in common sorting tasks.
- a compensating algorithm for .
- a type of sorting technique based on or data structures.
- a typical DnC strategy in sorting tasks.
- a performant algorithm combined with both DnC and Randomization
- intro to several non-comparison based sorting algorithms
- Lecture Notes in Jan 16, 1996
- Lecture Notes, 2017
- Lecture notes, 2006