searching and sorting this process continuesone card at timeuntil all of the cards have been removed from the table and placed into our hand in their proper sorted position pick up the next card on top ( pick up the last card ( the resulting hand the insertion sort maintains collection of sorted items and collection of items to be sorted in the playing card analogythe deck represents the collection to be sorted and the cards in our hand represents those already sorted when implementing insertion sort in programthe algorithm maintains both the sorted and unsorted collections within the same sequence structure the algorithm keeps the list of sorted values at the front of the sequence and picks the next unsorted value from the first of those yet to be positioned to position the next itemthe correct spot within the sequence of sorted values is found by performing search after finding the proper positionthe slot has to be opened by shifting the items down one position python implementation of the insertion sort algorithm is provided in listing listing implementation of the insertion sort algorithm sorts sequence in ascending order using the insertion sort algorithm def insertionsorttheseq ) lentheseq starts with the first item as the only sorted entry for in range save the value to be positioned value theseq[ifind the position where value fits in the ordered part of the list pos while pos and value theseq[pos shift the items to the right during the search theseq[postheseq[pos pos - put the saved value into the open slot theseq[posvalue the insertionsort(function starts by assuming the first item is in its proper position nextan iteration is performed over the remaining items so each value can be inserted into its proper position within the sorted portion of the sequence the ordered portion of the sequence is at the front while those yet to be inserted are at the end the loop index variable marks the separation point between the two parts the inner loop is used to find the insertion point within the sorted sequence and at the same timeshifts the items down to make room for the next item thusthe inner loop starts from the end of the sorted subsequence and