Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hhoopes/dee147ff70e6a4c25115bff576cd081f to your computer and use it in GitHub Desktop.
Save hhoopes/dee147ff70e6a4c25115bff576cd081f to your computer and use it in GitHub Desktop.
**Step One**: Watch [Sorting Algorithms in JavaScript](https://www.youtube.com/watch?v=uRyqlhjXYQI)
**Step Two**: Fork this gist.
**Step Three**: Respond to this question in your fork: "What are some of the balances and trade offs between different sorting algoritms?"
This is a good question to think about, because I'm helping the mod 1 students with their sorting suites!
There are three considerations for a sorting algo: stability (maintaining the fidelity of a collection with the criteria given), runtime, actual implementation.
Merge sort is stable, fast, and used by most browsers, but insertion sort is often used once groups become smaller. Insertion sort should only be used on small groups though, because it has a nested loop, which creates n squared runtime. It also has the benefit of a simple implementation.
Bubble sort is so slow because even if the array is already sorted, it still requires 2n iterations and usually isn't considered a viable option.
Merge sort on a large amount data can't be done in the browser because it requires so much memory and the browser might choke on the recursion. But it's a quicker sort than either bubble or merge for large amounts of data.
The general theme is that choosing a sorting algorithm for a project isn't a simple answer, but requires knowing the constraints of the project.
**Step Four**: _Totally Optional_: take a look at some of the other forks and comment if the spirit moves you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment