Sorting Algorithms

Bubble Sort

The Code

Bubble

Advantages:

  • Bubble sort uses very little memory as it is a small and simple algorithm (it simply compares to items and swaps them).

Disadvantages:

  • It is slow, if there are 10 items to sort, then each pass will require 9 comparisons. You may need up to 9 passes to sort the data.

Merge Sort

The Code

Merge

Advantages

  • It is substantially faster for almost all lists as it requires less steps (if a short list was almost sorted already, it may be faster to use a bubble sort).

Disadvantages

  • Merge sort uses more memory as a new array is created using the values from the old list. In bubble sort the list itself is sorted.
%d bloggers like this: