write an algorithm for inserting a card in a list of sorted cards
Answers
Answered by
6
Insertion Sort is an efficient algorithm for sorting a small number of elements. It is similar to sort a hand of playing cards.
Playing a card is one of the techniques of sorting and in Insertion Sort we follow following steps.
– Start with an empty left hand and cards face down on the table.
– Then remove one card at a time from the table and Insert it into the correct position in the left hand.
– To find a correct position for a card, we compare it with each of the cards already in the hand from right to left.
In the same way, Insertion Sort works….The numbers that we wish to sort are known as Keys. Although conceptually we are sorting a sequence, then input comes to us in the form of an array with n elements.
Playing a card is one of the techniques of sorting and in Insertion Sort we follow following steps.
– Start with an empty left hand and cards face down on the table.
– Then remove one card at a time from the table and Insert it into the correct position in the left hand.
– To find a correct position for a card, we compare it with each of the cards already in the hand from right to left.
In the same way, Insertion Sort works….The numbers that we wish to sort are known as Keys. Although conceptually we are sorting a sequence, then input comes to us in the form of an array with n elements.
Similar questions