Skip to content

Instantly share code, notes, and snippets.

@potatowagon
Last active October 14, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potatowagon/a1d0cd5027a030353b7a838138d432ff to your computer and use it in GitHub Desktop.
Save potatowagon/a1d0cd5027a030353b7a838138d432ff to your computer and use it in GitHub Desktop.
Sorting

Stable vs unstable

stable: keys always remain in the same order after sorting equal values

Before:
key:0  1  2  3
   [3][0][2][2]
   
After:
key:0  1  2  3
   [0][2][2][3]

unstable: key order is not nescessarily preserved

Before:
key:0  1  2  3
   [3][0][2][2]
   
After:
key:0  2  1  3
   [0][2][2][3]

bubble sort

quick sort

insertion sort

https://www.youtube.com/watch?v=JU767SDMDvA

selection sort

https://www.youtube.com/watch?v=g-PGLbMth_g

  1. have 2 pointers, min and curr
  2. in each iteration, find the min and swap with the start of the unsorted array
@potatowagon
Copy link
Author

potatowagon commented Oct 14, 2019

interesting visualisation of sorting https://www.youtube.com/watch?v=pcJHkWwjNl4

  1. selection sort
  2. insertion sort
    jist: they are the same, just different perspective

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