sorting
Quick Summary
In computer science, a sorting algorithm is a procedure for ordering elements within a list by following a specific sequence of steps. The primary goal of sorting is to make a list more usable, typically by arranging items in numerical order (from least to greatest or vice versa) or lexicographical order (similar to dictionary order).1
Sorting algorithms are fundamental to many applications, including search tools, data analysis, and e-commerce. Key factors in evaluating sorting algorithms are their computational complexity, which measures the time and memory required, and whether they are stable (preserving the order of equivalent elements) or unstable.1
Common sorting algorithms include:
* Selection Sort: Finds the minimum element and swaps it to the beginning, repeating for the rest of the list. It has a time complexity of O(n²).1
* Insertion Sort: Builds a sorted list by inserting elements from the unsorted portion into their correct positions. It also has an average time complexity of O(n²) but can be O(n) for already sorted lists.1
* Merge Sort: Uses a divide-and-conquer approach, splitting the list and merging sorted sublists. It has a time complexity of O(n log n).1
* Quicksort: Selects a pivot and partitions the list around it. Its average time complexity is O(n log n), but it can be O(n²) in the worst case.1
Ask Britannica AI about this topic
Britannica doesn't have a full article on this topic, so we've curated a list of our relevant coverage.
