1 / 9

Insertion Sort

Insertion Sort. Idea: like sorting a hand of playing cards Start with an empty left hand and the cards facing down on the table. Remove one card at a time from the table, and insert it into the correct position in the left hand

twedt
Download Presentation

Insertion Sort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Insertion Sort • Idea: like sorting a hand of playing cards • Start with an empty left hand and the cards facing down on the table. • Remove one card at a time from the table, and insert it into the correct position in the left hand • compare it with each of the cards already in the hand, from right to left • The cards held in the left hand are sorted • these cards were originally the top cards of the pile on the table Visit for more Learning Resources

  2. 24 10 6 Insertion Sort To insert 12, we need to make room for it by moving first 36 and then 24. 36 12

  3. 24 10 6 Insertion Sort 36 12

  4. 24 36 Insertion Sort 10 6 12

  5. Insertion Sort input array 5 2 4 6 1 3 at each iteration, the array is divided in two sub-arrays: left sub-array right sub-array unsorted sorted

  6. Insertion Sort

  7. *-*-* (Way of working) *-*-* Select – Compare – Shift - Insert

  8. Algorithm

  9. when we can use Insertion Sort ? • This method is effective when dealing with small numbers . • Applications using insertion sort • Mathematical applications : in the search for greater value, or the smallest value. • In many other applications.  For more detail contact us

More Related