Sorting

  • many sorting and searching problems are tweaks of well-known algorithms
  • a good approach is to run through the different sorting algorithms and see if one applies particularly well

Common Sorting Algorithms:

AlgorithmDescriptionTime ComplexityMemory
Bubble SortRepeatedly swaps adjacent elements if needed.O(n^2) (average/worst)O(1)
Selection SortSelects the smallest element in each pass.O(n^2)O(1)
Merge SortDivides the array and merges sorted halves.O(n log n)O(n)
Quick SortPartitions array and sorts recursively.O(n log n) (average)O(log n)
Radix SortSorts by processing digits from least to most.O(nk)O(n + k)
Bucket SortDistributes data into ranges and sorts buckets.O(n + k) (average)O(n + k)