What are the main sorting algorithms and their complexities?

Computer Science

ScanSolve AI Answer

Bubble Sort: O(n²) — compare adjacent pairs, swap if wrong order. Simple but slow. Selection Sort: O(n²) — find minimum, place at front. Insertion Sort: O(n²) — insert each element into sorted portion. Good for small/nearly sorted data. Merge Sort: O(n log n) — divide in half, sort each, merge. Stable, consistent. Quick Sort: O(n log n) average, O(n²) worst — pick pivot, partition. Fastest in practice. Heap Sort: O(n log n) — uses binary heap. For most cases, use your language's built-in sort (usually Timsort, a hybrid).

Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question