Sorting Rubyists

Sorting Rubyists

We'll visualize the steps for several sorting algorithms not only using pretty visualizations on a slide, but also with people as the objects being sorted. Don't know what an algorithm is, what performance really means, or what "Big O" means, or what these best-, worst-, and average-case time complexities mean? No problem! We're going to learn together how computers figure out how to sort sets of numbers. You can expect to come out knowing new things and with Benny Hill stuck in your head.

We'll visualize several sorting algorithms---but we'll be sorting the audience! Don't know what an algorithm is, what performance means, what "Big O" is, or the effect best-, worst-, and average-case time complexities? No problem: we'll learn together! You can expect to come out knowing new things and with Benny Hill stuck in your head.

Source code and notes: https://calebhearth.com/talks/sorting-rubyists

A438eb5b27da0f50dc120f9bfbdd9c16?s=128

Caleb Hearth

March 31, 2017
Tweet

Transcript

  1. "Sorting" <=> "Rubyists"

  2. None
  3. 1000

  4. 1000 = 30

  5. 1000 = 30

  6. None
  7. ..

  8. ..

  9. Algorithms

  10. A series of step-by-step instructions

  11. t

  12. None
  13. :14

  14. Big O

  15. None
  16. None
  17. 0 2 4 6 8 10 0 1 2 3

    4 5 6 7 8 9 10 O(n) n
  18. None
  19. 0 2 4 6 8 10 0 1 2 3

    4 5 6 7 8 9 10 O (log n )
  20. 0 250 500 750 1000 1 4 7 10 13

    16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 100 O(n) O(1) O(log n) O(n log n) O(n^2) O(2^n) O(n!)
  21. 0 25 50 75 100 1 4 7 10 13

    16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 100 O(n) O(1) O(log n) O(n log n) O(n^2) O(2^n) O(n!)
  22. When do you update a user record?

  23. When do you update a user record? O ( n

    log n )
  24. If you understood everything

  25. If you understood everything I’m really it today O(n)

  26. How do you debug an app?

  27. How do you debug an app? Start O (log n

    )
  28. What happens when you buy something?

  29. What happens when you buy something? You it O(n)

  30. Big Ω

  31. Bubble Sort

  32. !"#"$"%"&"'"(")"*"+",

  33. !"#"$"%"&"'"(")"*"+",

  34. !"#"$"%"&"'"(")"*"+",

  35. !"$"#"%"&"'"(")"*"+",

  36. !"$"#"%"&"'"(")"*"+",

  37. !"$"%"#"&"'"(")"*"+",

  38. !"$"%"#"&"'"(")"*"+",

  39. !"$"%"&"#"'"(")"*"+",

  40. !"$"%"&"#"'"(")"*"+",

  41. !"$"%"&"'"#"(")"*"+",

  42. !"$"%"&"'"#"(")"*"+",

  43. !"$"%"&"'"("#")"*"+",

  44. !"$"%"&"'"("#")"*"+",

  45. !"$"%"&"'"(")"#"*"+",

  46. !"$"%"&"'"(")"#"*"+",

  47. !"$"%"&"'"(")"*"#"+",

  48. !"$"%"&"'"(")"*"#"+",

  49. !"$"%"&"'"(")"*"+"#",

  50. !"$"%"&"'"(")"*"+"#",

  51. !"$"%"&"'"(")"*"+"#",

  52. !"$"%"&"'"(")"*"+"#",

  53. !"$"%"&"'"(")"*"+"#",

  54. !"%"$"&"'"(")"*"+"#",

  55. !"%"$"&"'"(")"*"+"#",

  56. !"%"&"$"'"(")"*"+"#",

  57. !"%"&"$"'"(")"*"+"#",

  58. !"%"&"'"$"(")"*"+"#",

  59. !"%"&"'"$"(")"*"+"#",

  60. !"%"&"'"("$")"*"+"#",

  61. !"%"&"'"("$")"*"+"#",

  62. !"%"&"'"(")"$"*"+"#",

  63. !"%"&"'"(")"$"*"+"#",

  64. !"%"&"'"(")"*"$"+"#",

  65. !"%"&"'"(")"*"$"+"#",

  66. !"%"&"'"(")"*"+"$"#",

  67. !"%"&"'"(")"*"+"$"#",

  68. !"%"&"'"(")"*"+"$"#",

  69. !"%"&"'"(")"*"+"$"#",

  70. %"!"&"'"(")"*"+"$"#",

  71. %"!"&"'"(")"*"+"$"#",

  72. %"&"!"'"(")"*"+"$"#",

  73. %"&"!"'"(")"*"+"$"#",

  74. %"&"'"!"(")"*"+"$"#",

  75. %"&"'"!"(")"*"+"$"#",

  76. %"&"'"!"(")"*"+"$"#",

  77. %"&"'"!")"("*"+"$"#",

  78. %"&"'"!")"("*"+"$"#",

  79. %"&"'"!")"*"("+"$"#",

  80. %"&"'"!")"*"("+"$"#",

  81. %"&"'"!")"*"+"("$"#",

  82. %"&"'"!")"*"+"("$"#",

  83. %"&"'"!")"*"+"("$"#",

  84. %"&"'"!")"*"+"("$"#",

  85. %"&"'"!")"*"+"("$"#",

  86. %"&"'"!")"*"+"("$"#",

  87. %"&"'"!")"*"+"("$"#",

  88. %"&"'")"!"*"+"("$"#",

  89. %"&"'")"!"*"+"("$"#",

  90. %"&"'")"*"!"+"("$"#",

  91. %"&"'")"*"!"+"("$"#",

  92. %"&"'")"*"+"!"("$"#",

  93. %"&"'")"*"+"!"("$"#",

  94. %"&"'")"*"+"!"("$"#",

  95. %"&"'")"*"+"!"("$"#",

  96. %"&"'")"*"+"!"("$"#",

  97. %"&"'")"*"+"!"("$"#",

  98. %"&")"'"*"+"!"("$"#",

  99. %"&")"'"*"+"!"("$"#",

  100. %"&")"'"*"+"!"("$"#",

  101. %"&")"'"+"*"!"("$"#",

  102. %"&")"'"+"*"!"("$"#",

  103. %"&")"'"+"*"!"("$"#",

  104. %"&")"'"+"*"!"("$"#",

  105. %"&")"'"+"*"!"("$"#",

  106. %")"&"'"+"*"!"("$"#",

  107. %")"&"'"+"*"!"("$"#",

  108. %")"&"'"+"*"!"("$"#",

  109. %")"&"+"'"*"!"("$"#",

  110. %")"&"+"'"*"!"("$"#",

  111. %")"&"+"'"*"!"("$"#",

  112. %")"&"+"'"*"!"("$"#",

  113. )"%"&"+"'"*"!"("$"#",

  114. )"%"&"+"'"*"!"("$"#",

  115. )"%"&"+"'"*"!"("$"#",

  116. )"%"&"+"'"*"!"("$"#",

  117. )"%"&"+"'"*"!"("$"#",

  118. 2) n O(

  119. 2) O(set.length

  120. 2) n O(

  121. ⌦(n)

  122. 0 250 500 750 1000 1 4 7 10 13

    16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 100 O(n) O(1) O(log n) O(n log n) O(n^2) O(2^n) O(n!)
  123. https://www.toptal.com/developers/sorting-algorithms/bubble-sort Random Nearly Sorted Reversed Few Unique

  124. https://www.toptal.com/developers/sorting-algorithms/bubble-sort Random Nearly Sorted Reversed Few Unique

  125. Insertion Sort

  126. ("#","&"+"%"-"*"$"'"!

  127. ("#","&"+"%"-"*"$"'"!

  128. ("#","&"+"%"-"*"$"'"!

  129. ("#","&"+"%"-"*"$"'"!

  130. ("#","&"+"%"-"*"$"'"!

  131. ("#","&"+"%"-"*"$"'"!

  132. ("#","&"+"%"-"*"$"'"!

  133. ("#","&"+"%"-"*"$"'"!

  134. ("#","&"+"%"-"*"$"'"!

  135. ("#","&"+"%"-"*"$"'"!

  136. ("#","&"+"%"-"*"$"'"!

  137. &"("#","+"%"-"*"$"'"!

  138. &"("#","+"%"-"*"$"'"!

  139. &"("#","+"%"-"*"$"'"!

  140. &"("#","+"%"-"*"$"'"!

  141. &"("#","+"%"-"*"$"'"!

  142. &"("#","+"%"-"*"$"'"!

  143. &"+"("#","%"-"*"$"'"!

  144. &"+"("#","%"-"*"$"'"!

  145. &"+"("#","%"-"*"$"'"!

  146. &"+"("#","%"-"*"$"'"!

  147. &"+"("#","%"-"*"$"'"!

  148. &"+"("#","%"-"*"$"'"!

  149. &"+"("#","%"-"*"$"'"!

  150. %"&"+"("#","-"*"$"'"!

  151. %"&"+"("#","-"*"$"'"!

  152. %"&"+"("#","-"*"$"'"!

  153. %"&"+"("#","-"*"$"'"!

  154. %"&"+"("#","-"*"$"'"!

  155. %"&"+"("#","-"*"$"'"!

  156. %"&"+"("#","-"*"$"'"!

  157. %"&"+"("#","-"*"$"'"!

  158. -"%"&"+"("#","*"$"'"!

  159. -"%"&"+"("#","*"$"'"!

  160. -"%"&"+"("#","*"$"'"!

  161. -"%"&"+"("#","*"$"'"!

  162. -"%"&"+"("#","*"$"'"!

  163. -"%"&"+"("#","*"$"'"!

  164. -"%"&"+"*"("#","$"'"!

  165. -"%"&"+"*"("#","$"'"!

  166. -"%"&"+"*"("#","$"'"!

  167. -"%"&"+"*"("#","$"'"!

  168. -"%"&"+"*"("#","$"'"!

  169. -"%"&"+"*"("$"#","'"!

  170. -"%"&"+"*"("$"#","'"!

  171. -"%"&"+"*"("$"#","'"!

  172. -"%"&"+"*"("$"#","'"!

  173. -"%"&"+"*"("$"#","'"!

  174. -"%"&"+"*"("$"#","'"!

  175. -"%"&"+"*"("$"#","'"!

  176. -"%"&"+"*"("$"#","'"!

  177. -"%"&"+"'"*"("$"#","!

  178. -"%"&"+"'"*"("$"#","!

  179. -"%"&"+"'"*"("$"#","!

  180. -"%"&"+"'"*"("$"#","!

  181. -"%"&"+"'"*"("$"#","!

  182. -"%"&"+"'"*"("$"#","!

  183. -"%"&"+"'"*"("$"#","!

  184. -"%"&"+"'"*"!"("$"#",

  185. -"%"&"+"'"*"!"("$"#",

  186. 2) n O(

  187. ⌦(n)

  188. https://www.toptal.com/developers/sorting-algorithms/insertion-sort Random Nearly Sorted Reversed Few Unique

  189. https://www.toptal.com/developers/sorting-algorithms/insertion-sort Random Nearly Sorted Reversed Few Unique

  190. Quicksort

  191. #"-"%"'"&","("$"!"*"+

  192. #"-"%"'"&","("$"!"*"+

  193. #"-"%"'"&"("$"!"*"+",

  194. #"-"%"'"&"("$"!"*"+",

  195. -"%"'"&"!"*"+"("#"$",

  196. -"%"'"&"!"*"+"("#"$",

  197. -"%"&"'"!"*"+"("#"$",

  198. -"%"&"'"!"*"+"("#"$",

  199. -"%"&"'"!"*"+"("#"$",

  200. -"%"&"'"!"*"+"("#"$",

  201. -"%"&"'"+"*"!"("#"$",

  202. -"%"&"'"+"*"!"("#"$",

  203. -"%"&"+"'"*"!"("#"$",

  204. -"%"&"+"'"*"!"("#"$",

  205. -"%"&"+"'"*"!"("$"#",

  206. -"%"&"+"'"*"!"("$"#",

  207. -"%"&"+"'"*"!"("$"#",

  208. -"%"&"+"'"*"!"("$"#",

  209. -"%"&"+"'"*"!"("$"#",

  210. -"%"&"+"'"*"!"("$"#",

  211. 2) n O(

  212. #"-"%"'"&","("$"!"*"+

  213. #"-"%"'"&"("$"!"*"+",

  214. O ( n log n )

  215. ⌦( n log n )

  216. https://www.toptal.com/developers/sorting-algorithms/quick-sort Random Nearly Sorted Reversed Few Unique

  217. https://www.toptal.com/developers/sorting-algorithms/quick-sort Random Nearly Sorted Reversed Few Unique

  218. Bubble Random Nearly Sorted Reversed Few Unique Insertion Quick

  219. Bubble Random Nearly Sorted Reversed Few Unique Insertion Quick

  220. None
  221. None
  222. None
  223. None
  224. None
  225. Gracias.

  226. Bibliography • Pollice, G., Selkow, S., Heineman, G.T. (2008). Algorithms

    in a Nutshell. O’Reilly Media, Inc. • Bhargava, A. (2016). Grokking Algorithms. Manning Publications. • du Sautoy, M. (Presenter), Overton, P. (Producer). (2015, September 24). The Secret Rules of Modern Living: Algorithms [Television broadcast]. London, UK: BBC Four. • Yukihiro, M. (1996). Array.sort!. Ruby [Software]. Retrieved 2017, March 27 from https://github.com/ruby/ruby/blob/ 47563655037ed453607de33b86fcc094878769ac/ array.c#L2431-L2513.
  227. Images • Toptal. (2010). [Sorting Algorithms Animations]. Retrieved March 26,

    2017, from https://www.toptal.com/developers/sorting-algorithms • Cortesi, A. (2010). [sorting algorithm visualization]. Retrieved March 26, 2017, from http://sortvis.org/ • http://chocolate.wikia.com/wiki/Chocolate_Chip_Cookie • https://www.babble.com/best-recipes/anatomy-of-a-chocolate-chip-cookie/ • http://thequotablekitchen.com/thick-chewy-chocolate-chip-cookies/ • http://www.beachwoodreporter.com/tv/what_i_watched_last_night_55.php • http://asegrad.tufts.edu/academics/explore-graduate-programs/computer- science
  228. Funography • https://www.youtube.com/watch?v=kPRA0W1kECg • https://www.youtube.com/watch?v=gOKVwRIyWdg • Big O and Big

    Omega graphics: https://texblog.org/ 2014/06/24/big-o-and-related-notations-in-latex/