Skip to content

Types of Sorting

Bubble Sort

  • Iterates through the array, comparing adjacent elements and swapping them if they're in the wrong order. Repeats this process until the array is sorted.

Quick Sort

  • Chooses a 'pivot' element and partitions the array into smaller subarrays, placing elements smaller than the pivot to its left and elements larger than the pivot to its right. Recursively sorts these subarrays.

Selection Sort

  • Divides the array into sorted and unsorted portions. Finds the smallest element in the unsorted section and swaps it with the first unsorted element. Repeats until the array is sorted.

Insertion Sort

  • Builds the sorted array one element at a time by iterating through the array and placing each element in its correct position within the sorted portion.

Merge Sort

  • Divides the array into smaller subarrays until each subarray contains only one element. Merges these subarrays in sorted order until the entire array is sorted.

Heap Sort

  • Builds a heap from the array, rearranging the elements to form a heap data structure. Repeatedly extracts the maximum element from the heap and rebuilds the heap until the array is sorted.