Sorting Algorithms

Learn about different sorting techniques and their implementations

Bubble Sort
Time Complexity: O(n²) | Space Complexity: O(1)

A simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

Difficulty: Easy
Selection Sort
Time Complexity: O(n²) | Space Complexity: O(1)

An in-place comparison sorting algorithm that divides the input list into two parts: a sorted sublist and an unsorted sublist.

Difficulty: Easy
Insertion Sort
Time Complexity: O(n²) | Space Complexity: O(1)

Builds the final sorted array one item at a time. It's much less efficient on large lists than more advanced algorithms.

Difficulty: Easy
Merge Sort
Time Complexity: O(n log n) | Space Complexity: O(n)

An efficient, stable, divide-and-conquer algorithm that divides the input array into two halves, recursively sorts them, and then merges the sorted halves.

Difficulty: Medium
Quick Sort
Time Complexity: O(n log n) average, O(n²) worst | Space Complexity: O(log n)

An efficient, in-place sorting algorithm that uses a divide-and-conquer strategy with a pivot element to partition the array.

Difficulty: Medium
Heap Sort
Time Complexity: O(n log n) | Space Complexity: O(1)

A comparison-based sorting algorithm that uses a binary heap data structure to build a max-heap and then repeatedly extracts the maximum element.

Difficulty: Medium
Counting Sort
Time Complexity: O(n + k) | Space Complexity: O(n + k)

A non-comparison-based sorting algorithm that works well when there is a limited range of input values.

Difficulty: Medium
Radix Sort
Time Complexity: O(nk) | Space Complexity: O(n + k)

A non-comparative sorting algorithm that sorts data with integer keys by grouping keys by individual digits that share the same position and value.

Difficulty: Hard