Skip to content

Instantly share code, notes, and snippets.

@acareaga
Forked from stevekinney/gist:9e9cfeb225c8133fda73
Last active February 16, 2016 22:01
Show Gist options
  • Save acareaga/3bd0b1e5578586bb9dc3 to your computer and use it in GitHub Desktop.
Save acareaga/3bd0b1e5578586bb9dc3 to your computer and use it in GitHub Desktop.
EmpireJS - Sorting Algorithms

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

Everying 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
@rrgayhart
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment