Sorting Algorithms – Bubble, Merge, Insertion

What are some of the balances and trade offs between different sorting algorithms?

Everything we’re dealing with is sorting arrays. Consider Speed vs. Space when deciding what algorithm to use.

Notes:

  • Insertion: good for small data sets and sorting in the browser, stable (alex before adam, etc.), doesn’t take much space
  • Bubble: looks similar to insertion sort, even if array is sorted we’re checking through every item (slow)
  • Merge: recursively split array to sort then merge (divide & conquer), won’t work with a lot of data in the browser (memory constraint)

Pros:

  • Insertion: low resources needed, fast for nearly-sorted data
  • Bubble: easy to implement, cool name
  • Merge: fast, stable

Cons:

  • Insertion: slow when data is reverse order
  • Bubble: slow, unstable
  • Merge: needs resources for temp space and arrays from recursive calls

 

Advertisements