Sorting Algorithms Flashcards
Sorting Algorithms
Sorting algorithms are methods for arranging elements in a specific order, typically in ascending or descending order. Common sorting algorithms include Quick Sort, Merge Sort, Bubble Sort, and Insertion Sort.
Quick Sort
Quick Sort is a highly efficient, in-place, and divide-and-conquer sorting algorithm. It works by selecting a ‘pivot’ element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then recursively sorted.
Merge Sort
Merge Sort is a stable and efficient sorting algorithm that uses a divide-and-conquer approach. It divides the unsorted list into n sublists, each containing one element, and then repeatedly merges sublists to produce new sorted sublists until there is only one sublist remaining, which is the sorted list.
Bubble Sort
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, indicating that the list is sorted.
Insertion Sort
Insertion Sort is a simple sorting algorithm that builds the final sorted array one item at a time. It works by repeatedly taking an unsorted element and inserting it into its correct position within the sorted part of the array. It has a time complexity of O(n^2) on average but performs well for small datasets.