Toggle search
Search
Toggle menu
notifications
Toggle personal menu
Editing
Insertion sort
From OpenCourse
Views
Read
Edit
Edit source
View history
associated-pages
Page
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Insertion sort is a method of sorting a list. It is very simple - it simply takes each item and loops through the (semi) sorted list to put it in the right place. It uses the first item in the list as a 'starting-point' == Algorithm == # Look at the second item in a list. # Compare it to all the items that are before it and insert the number in the correct place. # Repeat {2} for all subsequent items in the list. == Advantages == * Intuitive way of sorting things * Easy to implement (code) * Low memory usage * Very quick to add items (if list is ordered) * Works well with small lists * Quick to check if list is already sorted. == Disadvantages == Like the bubble sort, it doesn't work efficiently with larger lists. == Speed of insertion sort == In the best case scenario (already ordered list), it takes '''n-1''' comparisons. In the worst-case scenario, it takes '''n(n-1) / 2''' comparisons.
Summary:
Please note that all contributions to OpenCourse are considered to be released under the Public Domain (see
OpenCourse:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)