Introduction to insertion sort
Insertion sort is a sorting algorithm that builds the final sorted list by simply moving the items to their correct positions one at a time. It's not the most efficient algorithm and follows a brute-force approach (it tries the straightforward strategy of comparing and shifting one element at a time rather than using a cleverer divide-and-conquer trick), but it's simple to understand and implement.
Is insertion sort faster than bubble and selection sorts?
In practical application, insertion sort is a better performer than bubble or selection sorts, as, on average, it makes fewer comparisons to sort data.
In practical application, insertion sort is a better performer than bubble or selection sorts, as, on average, it makes fewer comparisons to sort data.
Example
An intuitive example of insertion sort can be seen when arranging a hand of cards in ascending order.
Random deck of cards
Liking the course? Check our discounted plans to continue learning.