• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking
computinglesson.com

Sorting algorithms

Excellent animation of eight different sorting algorithms

Insertion Sort

Picture
The insertion sort corresponds to a natural, human approach to sorting.   It's the way that you probably do it in real life.

For each item to be sorted, look through the list of items in order and insert it in sequence.

To understand the pseudocode, consider that the list can be divided into a sorted part (to the left) and an unsorted part (to the right)
for each item in list
   store the item value in a temporary variable 'key'
   set 'found' flag to false
   set 'place' variable to position - 1 (to the left)
   repeat
      compare key to the item[place]
      if key is smaller, 
            copy item[place] to item[place+1]
            put key in item[place]

      if key is larger, then set found to true
   until found is true or place is 0
next

Quick Sort

Picture
Quicksort was invented in 1960 in Russia by Tony Hoare.  It's a classic recursive algorithm.

Wikipedia has an excellent article on quicksort
Powered by Create your own unique website with customizable templates.