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

(RubyConf 2016) Computer Science: The Good Parts

Jeff Cohen
November 09, 2016

(RubyConf 2016) Computer Science: The Good Parts

My keynote talk from RubyConf 2016 in Cincinnati.

Jeff Cohen

November 09, 2016
Tweet

More Decks by Jeff Cohen

Other Decks in Programming

Transcript

  1. Complexity A "green" test suite is not an indicator of

    sustainability. Some implementations are more complex than others. • Time • Space
  2. def exists?(name_to_find, names) names.each do |name| return true if name

    == name_to_find end return false end O(n) 0 100 200 300 O(n)
  3. O(log n) def exists?(name_to_find, sorted_names) 
 
 midpoint = sorted_names.length

    / 2 
 return true if sorted_names[midpoint].name == name_to_find 
 if name < sorted_names[midpoint].name 
 search(name_to_find, sorted_names[0, midpoint]) 
 else 
 search(name_to_find, sorted_names[midpoint, -1]) 
 end 
 return false
 end
  4. def exists?(name_to_find, sorted_names) 
 
 midpoint = sorted_names.length / 2

    
 return true if sorted_names[midpoint].name == name_to_find 
 if name < sorted_names[midpoint].name 
 search(name_to_find, sorted_names[0, midpoint]) 
 else 
 search(name_to_find, sorted_names[midpoint, -1]) 
 end 
 return false
 end O(log n) 0 100 200 300 O(log n) O(n)
  5. O(n2) def make_combinations(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]]
  6. O(n2) def make_combinations(items) items.map do |item| items.map { |inner_item| [item,

    inner_item] } end end 0 100 200 300 O(n2) O(n) O(log n)
  7. 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.
  8. 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.