Course Hero Logo

Insertion sort.docx - Insertion sort is a simple sorting...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 3 pages.

Insertion sortis a simple sorting algorithm that works similar to the way yousort playing cards in your hands. The array is virtually split into a sorted and anunsorted part. Values from the unsorted part are picked and placed at thecorrect position in the sorted part.Characteristics of Insertion Sort:This algorithm is one of the simplest algorithm with simpleimplementationBasically, Insertion sort is efficient for small data valuesInsertion sort is adaptive in nature, i.e. it is appropriate for data setswhich are already partially sorted.Working of Insertion Sort algorithm:Consider an example: arr[]: {12, 11, 13, 5, 6}12111356First Pass:Initially, the first two elements of the array are compared in insertionsort.12111356Here, 12 is greater than 11 hence they are not in the ascending orderand 12 is not at its correct position. Thus, swap 11 and 12.So, for now 11 is stored in a sorted sub-array.11121356Second Pass:Now, move to the next two elements and compare them11121356Here, 13 is greater than 12, thus both elements seems to be inascending order, hence, no swapping will occur. 12 also stored in asorted sub-array along with 11Third Pass:Now, two elements are present in the sorted sub-array whichare11and12Moving forward to the next two elements which are 13 and 5
1112135
End of preview. Want to read all 3 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
sarah jeil
Tags
Bubble Sort, Insertion Sort, elements of the array, 12 13 5 6 11 Second

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture