insertion sort in python

Published: 29 August 2020
on channel: computing with sanjok
3
0

This is an in-place comparison-based sorting algorithm. Here, a sub-list is maintained which is always sorted. For example, the lower part of an array is maintained to be sorted. An element which is to be 'insert'ed in this sorted sub-list, has to find its appropriate place and then it has to be inserted there. Hence the name, insertion sort.

The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array). This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n2), where n is the number of items.

Algorithm:
Step 1 − If it is the first element, it is already sorted. return 1;
Step 2 − Pick next element
Step 3 − Compare with all elements in the sorted sub-list
Step 4 − Shift all the elements in the sorted sub-list that is greater than the
value to be sorted
Step 5 − Insert the value
Step 6 − Repeat until list is sorted


On this page of the site you can watch the video online insertion sort in python with a duration of hours minute second in good quality, which was uploaded by the user computing with sanjok 29 August 2020, share the link with friends and acquaintances, this video has already been watched 3 times on youtube and it was liked by 0 viewers. Enjoy your viewing!