Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Sorting Algorithms Cheat Sheet

Sorting Algorithms Cheat Sheet

Back to Mathematics and Algorithms
Updated 2026-05-25
Next Topic: Statistics Cheat Sheet

Sorting algorithms are fundamental procedures in computer science that rearrange elements in a collection according to a comparison operator. They form the backbone of data organization, enabling efficient searching, data analysis, and optimal algorithm performance across countless applicationsβ€”from database indexing to machine learning pipelines. While the theoretical lower bound for comparison-based sorting is \Omega(n \log n), the real-world performance varies dramatically based on input characteristics, memory hierarchy, and implementation details β€” Python 3.11 replaced TimSort with the provably near-optimal PowerSort, DeepMind's AlphaDev discovered assembly-level improvements of up to 70% for small fixed-size arrays, and IPS⁴o outperforms all known in-place and out-of-place parallel comparison sorts, proving the field far from settled.

What This Cheat Sheet Covers

This topic spans 18 focused tables and 101 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Core Comparison-Based SortsTable 2: Advanced Hybrid AlgorithmsTable 3: Non-Comparison SortsTable 4: Time Complexity AnalysisTable 5: Algorithm PropertiesTable 6: Pivot Selection StrategiesTable 7: Partitioning SchemesTable 8: Specialized Sorting AlgorithmsTable 9: Tree-Based SortsTable 10: Parallel and GPU SortsTable 11: External SortingTable 12: Stable In-Place SortsTable 13: Algorithm Selection GuidelinesTable 14: Optimization TechniquesTable 15: Sorting NetworksTable 16: Uncommon Specialized SortsTable 17: Algorithm Implementation DetailsTable 18: Inversions and Complexity Metrics

Table 1: Core Comparison-Based Sorts

The six foundational comparison-based algorithms every programmer should know. They differ sharply in stability, in-place memory use, and worst-case behavior β€” knowing when each one wins and when it collapses is the first layer of sorting mastery.

AlgorithmExampleDescription
QuickSort
pivot = arr[mid]
partition(arr, pivot)
quicksort(left, right)
β€’ Divide-and-conquer algorithm that selects a pivot and partitions array around it
β€’ average-case O(n \log n) but degrades to O(n^2) on poor pivot selection
β€’ fastest in practice for most random inputs; default basis for most production sort implementations.
MergeSort
divide(arr) β†’ [left, right]
merge(sorted_left, sorted_right)
β€’ Stable divide-and-conquer sort with guaranteed O(n \log n) time in all cases
β€’ requires O(n) auxiliary space for merging
β€’ excels with sequential access patterns, making it cache-friendly for large external datasets.
HeapSort
build_max_heap(arr)
extract_max() β†’ sorted
β€’ In-place sort using a binary max-heap structure
β€’ consistent O(n \log n) time with O(1) space; build-heap phase is O(n)
β€’ not stable; slower than QuickSort in practice due to poor cache locality from non-sequential access.
InsertionSort
for i in 1..n:
shift arr[i] left while > prev
β€’ Builds sorted array one element at a time by shifting
β€’ O(n^2) worst case but O(n) on nearly-sorted input
β€’ efficient for small arrays (n < 10–50) and used as base case in QuickSort, MergeSort, and TimSort.

More in Mathematics and Algorithms

  • Set Theory and Mathematical Relations Cheat Sheet
  • Statistics Cheat Sheet
  • Abstract Algebra Essentials Cheat Sheet
  • Complex Analysis Cheat Sheet
  • Graph Algorithms Shortest Paths and Network Search Cheat Sheet
  • Modular Arithmetic for Programming Cheat Sheet
View all 57 topics in Mathematics and Algorithms