Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshuajhun/a6556553cfd3cc55dc3a to your computer and use it in GitHub Desktop.
Save joshuajhun/a6556553cfd3cc55dc3a 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?"
**Step Four**: _Totally Optional_: take a look at some of the other forks and comment if the spirit moves you.
@joshuajhun
Copy link
Author

notes

-sort actually sorts items lexicographically.
-when sorting look at passing in a function. input [7,10,1] output = array.sort(function(a,b){return a-b}
-sorting benefits = stability, runtime analysis, alorithms implementation
-stable sort= maintain the relative order of item of equal values
-runtime analysis = not the be al and end all determinantts of best sorting
-couple of items out of place..

  • merge sort is fast, but takes a lot of space.

insertion sort
-compare each item to the item before it. if the one before it is greater we swap it.
-fairly quick!
- number of items is the nuber of opperations
- it's stable and great for small data sets
- a lot of space.
bubble sort - similar to insertion sort
- if the array is sorted we're still checking every item.
- the checking happens inside of th eloop
- goes through every item twice.
- nested for loops, easy to implemtn, unstable
merge sort - takes 20 lines of code
- involves recursion
- really fast
- multi branch its divide and conquer
- fast and stable.

This was a really interesting talk! I really enjoyed it and I feel like if I can begin to utilize these sorting algorhthms it will really help me clean up my code (which is the ultimate goal). So the main thing I got out of this is to not use bubble sort and that it's basically a teaching tool. It is it slow and unstable (sounds like me lol). Stability, speed and space tend to be the things you are considering when sorting. I feel like insertion sort is your first best option. It's great with small data sets and it's stable where as with merge sort although it's super fast it does require recursion and a lot more space.

@rrgayhart
Copy link

👍 Great answer!

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