Learning order

1. Recursion

Premium

Take a deep dive into one of the most intuitive programming paradigm

Show Index

2. Backtracking

Premium

Learn about the ultimate recursive brute force technique

Show Index

3. Sorting

Premium

Learn all about algorithms to sort data blazingly fast

Show Index

4. Searching

Premium

Learn about the algorithms that speed up your searches exponentially

Show Index

5. Dynamic Programming

Premium

Learn the most powerful optimization for recursive problems

(Early Access)

Show Index

6. Bit Manipulation

Premium

Learn about the fastest ways to manipulate data

(Early Access)

Show Index

What you will learn

Why O(N log N) is the comparison-sort lower bound and how counting sort beats it

The full mechanics of bubble, selection, insertion, quicksort, merge sort, and heapsort

Counting sort and Dutch national flag sort, both O(N) and both non-comparison

Quickselect for finding the kth smallest element in O(N) average time

Custom comparators for problems that order on a derived or transformed key

Stability, in-place behaviour, and adaptivity, and when each one actually matters

Why this course

Every modern language ships a default sort that handles 99% of production code without anyone thinking about it. The 1% it doesn't handle is what shows up in interviews. Which algorithm runs under .sort(). Whether the result is stable. How to find the kth smallest element without sorting the whole array. When to reach for quickselect over a full sort. The library call answers one question. The interview asks five.

This course walks you through nine sorting algorithms from bubble sort to heapsort, the classification axes (stable, in-place, adaptive, comparison versus counting) that decide which one to pick, and two reusable patterns, quickselect and custom comparators, that turn sorting into a problem-solving tool. You finish having implemented every algorithm yourself and solved 20 problems that interviewers actually ask.

Requirements

The course assumes you can code in any mainstream language and have used an array before, but no prior algorithmic background is needed.

  • Comfort writing loops, conditionals, and recursive functions in at least one language.
  • Familiarity with Big-O notation: O(N), O(N log N), O(N²), O(N + K).
  • Basic understanding of arrays and indexing. The Array course is a useful prerequisite if you have not taken it.

Overview

Sorting is the algorithm every higher-level operation quietly depends on. Binary search needs a sorted input. Merging streams needs sorted streams. Group-by aggregation runs in one pass once the data is sorted by key. Every modern language ships a default sort, sorted() in Python, Arrays.sort in Java, std::sort in C++, Array.prototype.sort in JavaScript, but the choice of algorithm underneath, Timsort, introsort, or dual-pivot quicksort, controls whether your code stays fast on near-sorted input or degrades when values repeat.

Representation of sorting

This course covers both halves: how each sorting algorithm actually works step by step, and how to recognise which problems collapse into a sort, a partial sort, or a custom ordering.

Fundamentals

The course opens with what sorting is and why disorganised data becomes unmanageable at scale. You see how binary search collapses from O(N) to O(log N) the moment an array is sorted, why grouped data processing requires sorted input, and how the O(N log N) comparison-sort lower bound is not a coincidence but a consequence of the decision-tree shape of any sort that only compares.

Next come the classification axes that every sorting algorithm trades off against: comparison versus counting, stable versus unstable, in-place versus out-of-place, adaptive versus non-adaptive. These map directly onto interview decisions. Pick a stable sort when a secondary key needs preserving. Pick an in-place sort under tight memory. Pick an adaptive sort when the input is nearly sorted. The course gives you the language to defend these choices instead of guessing.

From there you work through nine algorithms in order of growing sophistication. The quadratic family (bubble, selection, insertion) sets the baseline. Counting sort breaks the comparison lower bound for small value ranges. Quicksort, merge sort, and heapsort give you three different O(N log N) algorithms with very different memory and stability profiles. Dutch national flag sort and three-way quicksort handle the repeated-value case that vanilla quicksort fails on. Each algorithm is drawn step by step, then implemented as a question.

Problem solving

Sorting is not just a list of algorithms to memorise. Two recurring patterns sit on top of it, and once you see them the same template solves dozens of interview questions.

The 9 algorithms and 2 patterns you'll master
Bubble sort
Repeatedly swap adjacent out-of-order pairs to bubble larger values to the end of the array. Stable, in place, adaptive, with O(N²) average time and O(1) extra space. Implement Bubble Sort.
Selection sort
Scan the unsorted region for the minimum and swap it into the sorted prefix, using only N−1 swaps total. Unstable and in place, O(N²) time and O(1) space. Implement Selection Sort.
Insertion sort
Grow a sorted prefix by shifting larger elements right and inserting each new key into place. Stable, in place, adaptive, with O(N²) worst case and O(N) on nearly sorted input. Implement Insertion Sort.
Counting sort
Tally frequencies, build a cumulative-sum index, and place each value in O(N + K) time. Stable and out of place, and faster than any comparison sort when the value range K stays small. Implement Counting Sort.
Quicksort
Pick a random pivot, partition the array into smaller and larger halves, and recurse on each side. Unstable and in place, with O(N log N) average time and O(N²) worst case. Implement Quicksort, Top K Elements.
Dutch national flag sort
Partition an array of three distinct values into zero, one, and two regions in one O(N) pass using a left, mid, and right pointer. Unstable, in place, no recursion. Implement Dutch National Flag Sort.
Three-way quicksort
Combine Dutch national flag partitioning with recursive quicksort, skipping the equal-to-pivot band entirely. Beats classic quicksort whenever values repeat. Implement Three Way Quicksort.
Merge sort
Recursively split the array, sort each half, then merge sorted halves by comparing the front of each. Stable and out of place, O(N log N) time and O(N) extra space. Implement Merge Sort, Count Inversions.
Heapsort
Build a max heap from the array, then repeatedly swap the root to the end and heapify the shrinking heap region. Unstable and in place, O(N log N) time and O(1) extra space. Implement Heapsort.
Quickselect pattern
Replace value comparison with a scoring function and recurse only into the side that still contains the answer, finding top-k in O(N) average time without sorting the full array. Kth Smallest Element, Median Finder, K Closest Elements, K Most Frequent Elements.
Custom compare pattern
Define order by a transformation function: either transform on the fly inside the comparator, or precompute transformed values and sort by pairs. Bitwise Sort, Sort Characters By Frequency, Largest Number, Sort People By Height.

Each pattern is taught in three layers. An Understanding lesson works the pattern on a problem where the structure is obvious. An Identifying lesson teaches you the wording that flags a sort, quickselect, or comparator problem before you start coding: phrases like "kth smallest", "ordered by a derived key", or "without modifying the array". Then four problems give you progressively harder applications, from kth-smallest to largest-number. By the time you reach the custom comparator chapter, sorting has become a tool you reach for rather than an algorithm you fear.

How this course is different

Most material on sorting either lists the algorithms and stops, or jumps straight to LeetCode without teaching the trade-offs. This course addresses both.

Most DSA resources
This course
Show one or two sorting algorithms then move on, treating sorting as background knowledge.
Walks through nine algorithms, including counting sort, Dutch national flag, and three-way quicksort that most resources omit.
Skip the classification axes (stable, in place, adaptive), so you cannot defend a sort choice under questioning.
Drills the stability, in-place, and adaptive trade-offs so you can pick the right sort for the constraint you are given.
Cover quicksort and mergesort but never quickselect, Dutch national flag, or three-way quicksort.
Teaches quickselect as a standalone pattern that finds top-k in O(N) average time without sorting the full array.
Stop at how the algorithm works, never showing you when it actually appears in coding interview questions.
Treats custom comparators as a first-class pattern with transform-on-the-fly and precompute-and-pair variants.
Treat custom comparators as a syntax detail rather than a reusable problem-solving pattern.
Includes count inversions, k-most-frequent-elements, and largest-number, the kind of sorting questions interviewers actually ask.

Who this course is for

The course suits anyone who needs to actually understand sorting rather than guess which library call to use.

  • New programmers who can call a built-in sort but cannot name a single algorithm running underneath.
  • Self-taught and bootcamp graduates who know quicksort exists but have never implemented the partition step or explained the random pivot.
  • Working developers who need to pick a stable sort over an unstable one and are not sure which language built-ins guarantee what.
  • Engineers preparing for FAANG and Big Tech interviews where top-k, median, k-most-frequent, and inversion-counting questions appear regularly.
  • Returning engineers who learned sorts at university and want a clean refresher anchored in concrete problems rather than proofs.
  • Anyone who has memorised the quicksort code but cannot explain why a random pivot matters or when quickselect beats a full sort.

Continue your DSA journey

Sorting connects to nearly every other algorithmic topic. After this course, the natural next steps depend on where you want to go.

  • Array: Every sorting algorithm operates on an array. The memory model, indexing rules, and complexity vocabulary from the Array course are the foundation that makes an in-place swap obviously O(1) and a copy-based merge obviously O(N) extra space.
  • Hash table: Counting sort and hash tables both use a key-to-bucket map. Many problems are solvable either by sort or by hash, and the right choice depends on the value range, the stability requirement, and the memory budget.
  • Heap: Heapsort is the bridge between sorting and the heap data structure itself. The Heap course goes deeper on the priority queue, where the same heapify procedure powers Dijkstra, event simulation, and streaming top-k beyond what this course covers.
  • Recursion: Quicksort and merge sort are textbook divide-and-conquer recursions. The Recursion course teaches the call-stack model and recurrence-relation thinking that make those algorithms much easier to reason about.
  • Searching: Sorting and searching are companion topics. Once an array is sorted, binary search and its lower-bound and upper-bound variants unlock O(log N) lookups. Several array patterns also assume the input is pre-sorted before they apply.
  • Dynamic programming: Inversion counting in merge sort is a stepping stone to several DP problems, and sorting is one of the most common preprocessing steps that simplifies a DP recurrence on intervals or jobs.

Frequently asked questions

Code examples use Python for readability, but every algorithm (comparisons, swaps, partition steps, recursion) is language-agnostic. The course explicitly notes which built-ins (Python sorted, Java Arrays.sort, C++ std::sort, JavaScript Array.prototype.sort) are stable and which are not.
Yes. The course starts from why disorganised data is hard to work with and builds each algorithm step by step with drawings. If you can write a for loop, a recursive function, and read Big-O notation like O(N log N), you have everything you need.
There are around 28 lessons and 20 problems across 9 sorting algorithms and 2 patterns. Most learners finish the lessons in 10 to 14 hours and need another 12 to 20 hours to implement every algorithm and solve the pattern problems.
Yes. Quickselect (kth smallest, median, k closest, k most frequent), custom comparators (largest number, sort by frequency), counting sort, and merge-sort inversion counting are recurring interview topics, and the course drills the signals that let you spot them on first read.
LeetCode gives you problems with no organising structure. This course teaches the nine algorithms first, then the two patterns that sit on top of them, so you build pattern recognition rather than memorising solutions. You learn when quickselect beats sorting, not just that it exists.
Quicksort is usually faster on random in-memory data because it is in place, has tight cache behaviour, and a small constant factor. Merge sort is preferred when you need stability, predictable O(N log N) worst-case time (quicksort degrades to O(N²) on adversarial input without a random pivot), or external sorting on data that does not fit in RAM. Most language standard libraries actually ship a hybrid (Timsort, introsort) that switches between strategies based on input.
A stable sort preserves the relative order of elements that compare equal. Bubble, insertion, merge, and counting sort are stable; selection, quicksort, and heapsort are not. Stability matters whenever you sort by multiple keys in sequence (sort by name, then by department), or whenever the input order itself carries meaning (sort orders by price while keeping the original arrival order among ties). If you cannot guarantee stability when the problem needs it, your output is technically correct on the primary key but wrong on the secondary one.
Yes. Once you finish all lessons and solve the problems across both patterns, codeintuition issues a shareable certificate you can post to LinkedIn or attach to a job application.