Sorting Flashcards
downside of most most worst-case sorting algorithms that do optimally well in the worst-case
(notably heap sort and merge sort), do not take existing order within their input into account,
how to rectify mergesort not taking into account existing order of its input?
by checking if the last element of the lefthand group is less than (or equal) to the first element of the righthand group, in which case a merge operation may be replaced by simple concatenation – a modification that is well within the scope of making an algorithm adaptive.
list 8 adaptive sort algorithms
adaptive heap sort, adaptive merge sort, patience sort,[1] Shellsort, smoothsort, splaysort, straight insertion sort, and Timsort.
why are adaptive sorting algorithms attractive?
because nearly sorted sequences are common in practice
adaptive sort
A sorting algorithm falls into the adaptive sort family if it takes advantage of existing order in its input. It benefits from the presortedness in the input sequence – or a limited amount of disorder for various definitions of measures of disorder – and sorts faster. Adaptive sorting is usually performed by modifying existing sorting algorithms.
Permutation
permutation of a set is, loosely speaking, an arrangement of its members into a sequence or linear order, or if the set is already ordered, a rearrangement of its elements. The word “permutation” also refers to the act or process of changing the linear order of an ordered set.
How many permutations are there in a set of n elements?
n!
technically a permutation of set S is defined as what
a bijection from S to itself.[2][3] That is, it is a function from S to S for which every element occurs exactly once as an image value
The collection of all permutations of a set form what?
a group called the symmetric group of the set, where the group operation is the composition (performing two given rearrangements in succession), which results in another rearrangement
k-permutation
the number of arrangements of k items from n objects
How to denote a k permutation
It can be written as nPk (which reads “n permute k”)
nPk is equal to?
n(n−1)⋯(n−k+1)
aka
n!/(n−k)!
Insertion sort
InsertionSort(A) //[0, n-1]
For (i = 0 to ) let j = i + 1 while (j> 0 && A[j] > A[j-1]) swap(A, j, j-1) j—