Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. 6 Sorting

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🐙 Octopuses have three hearts and blue blood.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🦈 Sharks existed before trees 🌳.
Programming

    AI-AgenticAI

    AI-DeepLearning

    AI-GenAI

    AI-Infrastructure

    AI-Machine-Learning

    AI-Math

    AWS

    Azure

    kubernetes

    Management

    Programming
    • 🧱 Data Structures: Arrays, Stacks, Queues, Heaps, Hash Tables, Tries & Graphs


    • 🌲 Trees Deep Dive: BST, AVL Rotations, Red-Black Trees, B-Trees & B+ Trees


    • 🕸️ Graph Data Structures: Adjacency List vs Matrix, BFS & DFS


    • 🔢 Algorithmic Complexity: Big O From First Principles


    • Searching Algorithm & Their Complexity Complexity 🔎


    • ⚡ Sorting Algorithm Complexity 📖


    • 🗄️ Database Comparison 📖


    • Ansible: Agentless Configuration Management


    • CI/CD Pipelines: From Commit to Production


    • Unix Internals: Processes, File Descriptors, and Syscalls


    • Programming Index


    Terraform

    Z_Appendix

Cover Image for ⚡ Sorting Algorithm Complexity 📖
Programming

⚡ Sorting Algorithm Complexity 📖

Best, average, and worst case complexity and stability for Quick Sort, Merge Sort, Timsort, Heap Sort, and every other major sorting algorithm — quick revision notes.

Algorithms
Sorting
Big O
Complexity
Study Notes
← Previous

Searching Algorithm & Their Complexity Complexity 🔎

Next →

🗄️ Database Comparison 📖

⚡ Sorting Algorithm Complexity

#Algorithm⏱️ Best⚖️ Average🔻 Worst💾 Space⚙️ Stability
1⚡ Quick SortO(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(n2)O(n^2)O(n2)O(log⁡n)O(\log n)O(logn)❌ No
2🧩 Merge SortO(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(n)O(n)O(n)✅ Yes
3🚀 TimsortO(n)O(n)O(n)O(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(n)O(n)O(n)✅ Yes
4⛰️ Heap SortO(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(1)O(1)O(1)❌ No
5💧 Bubble SortO(n)O(n)O(n)O(n2)O(n^2)O(n2)O(n2)O(n^2)O(n2)O(1)O(1)O(1)✅ Yes
6✍️ Insertion SortO(n)O(n)O(n)O(n2)O(n^2)O(n2)O(n2)O(n^2)O(n2)O(1)O(1)O(1)✅ Yes
7🪞 Selection SortO(n2)O(n^2)O(n2)O(n2)O(n^2)O(n2)O(n2)O(n^2)O(n2)O(1)O(1)O(1)❌ No
8🌲 Tree SortO(nlog⁡n)O(n \log n)O(nlogn)O(nlog⁡n)O(n \log n)O(nlogn)O(n2)O(n^2)O(n2)O(n)O(n)O(n)❌ No
9🐚 Shell SortO(nlog⁡n)O(n \log n)O(nlogn)*~O(n1.3)O(n^{1.3})O(n1.3)O(n2)O(n^2)O(n2)O(1)O(1)O(1)❌ No
10🪣 Bucket SortO(n+k)O(n + k)O(n+k)O(n+k)O(n + k)O(n+k)O(n2)O(n^2)O(n2)O(n+k)O(n + k)O(n+k)✅ Yes**
11🔢 Radix SortO(nk)O(nk)O(nk)O(nk)O(nk)O(nk)O(nk)O(nk)O(nk)O(n+k)O(n + k)O(n+k)✅ Yes
12🧮 Counting SortO(n+k)O(n + k)O(n+k)O(n+k)O(n + k)O(n+k)O(n+k)O(n + k)O(n+k)O(k)O(k)O(k)✅ Yes

Notes

  • k = range of keys (Counting/Bucket Sort) or number of digits (Radix Sort).
  • *Shell Sort's complexity depends on the gap sequence; there is no universally accepted average-case complexity.
  • Bucket Sort is stable only if the sorting algorithm used within each bucket is stable (e.g., Insertion Sort).

Related Posts

  • 🧱 Data Structures & Big O Complexity — the Big O/Big Omega/Big Theta notation used throughout this comparison
  • 🔎 Searching Algorithm Complexity — Binary Search and other sorted-data-dependent searches this sorting step enables
Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Fri Feb 20 2026

Share This on

← Previous

Searching Algorithm & Their Complexity Complexity 🔎

Next →

🗄️ Database Comparison 📖

Programming/6-Sorting
Let's work together
hiteshkrsahu@gmail.com
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2026 All rights reserved.