Prof. Dr. Barne Kleinen

Website of Prof. Dr. Barne Kleinen, Professor for Media Informatics (Bachelor/Master) at HTW Berlin

Sorting Algorithms

Material in   Courses: Info2   Tags: Sorting  

..

AlgorithmDescriptionInvariantPlusO(n)ComparisionsSwapsStableadaptivespace
Selection Sortselect smallest from rest, append to already sorted on lefta[1..i] in placen^2n^2nnot stable
Insertion Sorttake card from unsorted pile (right), insert it into sorted pilea[1..i] sortedadaptable, simple -> ok for small nn^2n^2n^2stableyesO(1) extra
Shell SortInsertion sort on every h-th element decreasing h down to 1each h-array is sortedadaptable, still simplen^(3/2)stableyesO(1) extra
Bubble Sortgo up through array, compare two and swap if not in right order (up to 1..n)a[1..i] in placen^2n^2n^2stableyesO(1) extra
Merge Sortsplit in two, sort rec, merge two parts.predictable, works on linked listsn log n(0,5 to 1 )log n(1 to 1,5)log nstablenoO(n) extra
Quick Sortgo up through array, compare two and swap if not in right order (up to 1..n)a[1..k-1] < a[k] <= a[k+1..n]general purpose sort, but not stablen log n (n^2 worst)nonoO(n·lg(n)) for some optimizatiosn
Bogo Sortrandomly arrange array. If sorted, done.-n!n * n!n*n!not stablenoO(1)