Insertion Sort Algorithm

Insertion-sort-1-9The Insertion sort algorithm is one of the key sorting algorithms used in Computer Science.

To start with, the algorithm considers the first value of a list as a sorted sub-list (of one value to start with). This iterative algorithm then checks each value in the remaining list of values one by one. It inserts the value into the sorted sub-list of the data set in the correct position, moving higher ranked elements up as necessary.

This algorithm is an O(n2) algorithm which is relatively efficient for small lists and mostly sorted lists, and is often used as part of more sophisticated algorithms.

Python Implementation of an Insertion Sort algorithm


The Python code belows let you visualise how a Insertion sort algorithm with a small set of values (from 1 to 9). The list of values is shuffled every time you run this code.

Did you like this challenge?

Click on a star to rate it!

Average rating 3.3 / 5. Vote count: 27

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , ,