Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Latest commit

 

History

History
32 lines (18 loc) · 1.43 KB

File metadata and controls

32 lines (18 loc) · 1.43 KB

14 - Insertion sort

  • Insertion sort compareselements to the left of the current element, and inserts the current element in the correct position.

  • It has an O(n^2) time complexity, which makes it inefficient on large lists, and generally performs worse than the similar selection sort.

Visual Representation

Comparison

Algorithm Best Case Average Case Worst Case Space Complexity
Bubble Sort O(n) O(n^2) O(n^2) O(1)
Selection O(n^2) O(n^2) O(n^2) O(1)
Insertion O(n) O(n^2) O(n^2) O(1)
Recursion O(n log n) O(n log n) O(n^2) O(n)
Merge O(n log n) O(n log n) O(n log n) O(n)
Quick O(n log n) O(n log n) O(n^2) O(log n)

Materials


13 - Selection sort | Home | 15 - Recursion