Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Computer Science: The Good Parts

Computer Science: The Good Parts

Kansas City Developers Conference

Jeff Cohen

August 04, 2017
Tweet

More Decks by Jeff Cohen

Other Decks in Programming

Transcript

  1. 1. Encoding All The Things 2. Containers for Things 3.

    Doing Things 4. Building Big Things 5. Thinking About Things
  2. Stack 60 45 70 31 5 head New elements are

    inserted at the front of the list
  3. 60 31 5 45 80 70 74 99 87 68

    Binary
 Tree root
  4. Complexity A "green" test suite is not an indicator of

    sustainability nor is it a guarantee of an optimal solution.
  5. Complexity Science relies on standard systems of weights and measures.

    For software, we measure resources, which are typically time and space.
  6. O(n) def search(name_to_find, names) for name in names if name

    == name_to_find return true end end return false end
  7. def search(name_to_find, names) for name in names if name ==

    name_to_find return true end end return false end O(n) 0 100 200 300 O(n)
  8. O(log n) def search(name_to_find, sorted_names) 
 return false if sorted_names.size

    == 0 
 midpoint = sorted_names.length / 2 
 
 if name < sorted_names[midpoint].name 
 search(name_to_find, sorted_names[0, midpoint]) 
 elsif name > sorted_names[midpoint].name
 search(name_to_find, sorted_names[midpoint, -1]) end return true
 end
  9. def search(name_to_find, sorted_names) 
 return false if sorted_names.size == 0

    
 midpoint = sorted_names.length / 2 
 
 if name < sorted_names[midpoint].name 
 search(name_to_find, sorted_names[0, midpoint]) 
 elsif name > sorted_names[midpoint].name
 search(name_to_find, sorted_names[midpoint, -1]) end return true
 end O(log n) 0 100 200 300 O(log n) O(n)
  10. O(n2) def all_permuations(items) items.map do |item| items.map { |inner_item| [item,

    inner_item] } end end [1,2,3] => [[1,1], [1,2], [1,3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]
  11. Grace Hopper Humans are allergic to change. They love to

    say, "We've always done it this way." I try to fight that.
 
 That's why I have a clock on my wall that runs counter-clockwise.
  12. Grace Hopper A ship in port is safe; but that

    is not what ships are built for. Sail out to sea and do new things.