Insertion Sort

Insertion Sort


Insertion Sort

To search an ordered list a Binary Search is the best way, however the list needs to be put into that order in the first place, this is where the Insertion Sort comes in.

It consists of a number of passes thought the data and is quicker than a bubble sort

  • Starts by taking out the second item and comparing it to the items to the left of it, If they need to be moved then they are
  • Then looks at the third item and does the same
  • And so an and so fourth until its completed

Prodedure Sort (List, First, Last)

For CurrentPointer = First + 1 To Last

Current Value = List[CurrentPointer]

Pointer = CurrentPointer - 1

While List[Pointer] > CurrentValue and Pointer > 0

List[Pointer+1] = List[Pointer]


1 of 2


A value is found from the list called the Pivot Value. The list is then split into two, those higher and those lower than the pivot value, A new pivot value is found each time and items are swapped if necessary to finally order it all.

2 of 2





Similar Computing resources:

See all Computing resources »