DEV Community

ANISHA SWAIN | The UI Girl
ANISHA SWAIN | The UI Girl

Posted on • Originally published at theuigirl.hashnode.dev on

Concept Visualization for sorting of Array elements

Visualization-1

Insertion sort is one of the simplest ways of sorting a list of elements.

In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order.

Insertion sort is one of the simplest ways of sorting a list of elements. The algorithm is based on the idea that the position of an element will be decided based on its appropriate position in a sorted array. Each element in an array is positioned in each iteration, thereby the complexity is O(n) with O(n2) comparisons.

The resultant array increases by one element in each iteration. If the current element is greater, then it leaves the element in its place and moves on to the next element else it finds its correct position in the sorted array and moves it to that position. This is done by shifting all the elements one by one, that is larger than the current element, in the sorted array to one position ahead.

Make it more awesome

Insertion Sort is simple, adaptive and stable yet less efficient as compared to Quicksort, Heapsort or Heap sort.

So thats it for this article. I hope you have checked out the visualization and if you liked it then do not forget to tell us your thoughts in the comment section below.

If you want to connect with me, here I am at Twitter or Instagram

Announcement: we will be ding d3.js tutorials soon so stay tuned.

Follow our community LinkedIn group, Facebook Page and Twitter for more such articles and posts and meet like-minded people to collaborate.

Top comments (0)