The best programmers I’ve meet knew how to
    sort a deck of cards pretty d*mn well




               Tony Tran
Image source: http://www.flickr.com/photos/60601862@N00/942476116/
What if…


Given: Deck of playing cards
Goal: To retrieve any card as fast as
possible!
Constraints: No real constraints, ...
Find me:

    Approaches:
    1. Do nothing to the deck (Cost: 52 lookups)




Cost is analyzed in worst case scenario.
"A...
Approaches:
  1. Do nothing to the deck (Cost: 52 lookups)
  2. Group cards by suits (Cost: 4+12 = 16 lookups)




3. Grou...
Approaches:
  1. Do nothing to the deck (Cost: 52 lookups)
  2. Group cards by suits (Cost: 4+12 = 16 lookups)




       ...
Image source: http://www.eyebrowmagazine.com/__data/assets/image/0010/10045/megan_fox_naked_5.jpg
What if…
                                                                             …


Given: 99 note cards with a uniq...
Find me:

    Approaches:
     1. Do nothing to the deck (Cost: 99 lookups)
     2. Create bins for groups of 100 and just...
Find me:
    Approaches:
      1. Do nothing to the deck (Cost: 99 lookups)
      2. Create bins for groups of 100 and jus...
Find me:
    Approaches:
      1. Do nothing to the deck (Cost: 99 lookups)
      2. Create bins for groups of 100 and jus...
How does this apply to
                  programming?




Abstraction!
How does this apply to
                  programming?



   Programming Problem --> Real Life Problem

Abstraction!
Key point #1:
      1. Being able to abstract a problem to
      something less complex, or more familiar,
      will make...
Fans of abstraction




What is the shortest path from 1 to any other
node?
Keypoint #2:
Abstracting a problem to a problem that has already been solved is
even better! You don’t really have to do a...
Keypoint #3
         3. There’s no such thing as a dumb problem

   Problem: Given a spatula and a dish of pancakes (say 6...
Someone familiar:
SORTING PANCAKES == SORTING BY PREFIX REVERSAL




 Bill Gates & Christos Papadimitriou,
 Bounds For Sor...
Key Points:
1. Being able to abstract a problem to something less complex, or
more familiar, will make the problem easier!...
-THANK YOU-

New title proposal:
The best programmers I’ve meet knew how to ABSTRACT PROBLEMS pretty d*mn
well




    “Th...
Upcoming SlideShare
Loading in …5
×

The best programmers I’ve met knew how to sort a deck of cards pretty D*mn well.

2,440 views
2,237 views

Published on

Sorting a deck of cards and being an excellent programmer are two faces of the same coin. Programmers are often well respected for their abilities to manipulate bits of data. What is often overlooked is their ability to abstract difficult problems to instructions that a computer can understand and solve. In this talk, I will discuss the problem of sorting a deck of cards, and how such a problem can shed some insight into the mind of some of the greatest “Programmers.”

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,440
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

The best programmers I’ve met knew how to sort a deck of cards pretty D*mn well.

  1. 1. The best programmers I’ve meet knew how to sort a deck of cards pretty d*mn well Tony Tran
  2. 2. Image source: http://www.flickr.com/photos/60601862@N00/942476116/
  3. 3. What if… Given: Deck of playing cards Goal: To retrieve any card as fast as possible! Constraints: No real constraints, do whatever you want with the cards! Just don’t be a smart @s*! WHAT WOULD YOU DO!?!
  4. 4. Find me: Approaches: 1. Do nothing to the deck (Cost: 52 lookups) Cost is analyzed in worst case scenario. "Anything that can go wrong will go wrong.“ – Murphy’s Law
  5. 5. Approaches: 1. Do nothing to the deck (Cost: 52 lookups) 2. Group cards by suits (Cost: 4+12 = 16 lookups) 3. Group cards by faces (Cost: 12+4 = 16 lookups)
  6. 6. Approaches: 1. Do nothing to the deck (Cost: 52 lookups) 2. Group cards by suits (Cost: 4+12 = 16 lookups) =) 3. Group cards by faces (Cost: 12+4 = 16 lookups)
  7. 7. Image source: http://www.eyebrowmagazine.com/__data/assets/image/0010/10045/megan_fox_naked_5.jpg
  8. 8. What if… … Given: 99 note cards with a unique number written on each card. Goal: To retrieve any card as fast as possible! Constraints: No real constraints, do whatever you want with the cards! Just don’t be a smart @s*! WHAT WOULD YOU DO!?!
  9. 9. Find me: Approaches: 1. Do nothing to the deck (Cost: 99 lookups) 2. Create bins for groups of 100 and just throw the cards into the bin. Example: (Cost: 99 lookups) When given cards: 1,2,3,…,99 bins Cost is analyzed in worst case scenario. "Anything that can go wrong will go wrong.“ – Murphy’s Law
  10. 10. Find me: Approaches: 1. Do nothing to the deck (Cost: 99 lookups) 2. Create bins for groups of 100 and just throw the cards into the bin. (Cost: 99 lookups) 3. Sort the deck! Then perform binary search to find card. (cost: log2(99) lookups ~= 7 look ups) Depiction of binary search (does not show entire search) Cost is analyzed in worst case scenario. "Anything that can go wrong will go wrong.“ – Murphy’s Law
  11. 11. Find me: Approaches: 1. Do nothing to the deck (Cost: 99 lookups) 2. Create bins for groups of 100 and just throw the cards into the bin. (Cost: 99 lookups) 3. Sort the deck! Then perform binary search to find card. (cost: log2(99) lookups ~= 7 look ups) Depiction of binary search (does not show entire search) Cost is analyzed in worst case scenario. "Anything that can go wrong will go wrong.“ – Murphy’s Law
  12. 12. How does this apply to programming? Abstraction!
  13. 13. How does this apply to programming? Programming Problem --> Real Life Problem Abstraction!
  14. 14. Key point #1: 1. Being able to abstract a problem to something less complex, or more familiar, will make the problem easier! “the purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.” - Edsger W. Dijkstra Image source: http://www.scientificamerican.com/media/inline/3E0F9160-E7F2-99DF-358998AA3C1A910F_1.jpg
  15. 15. Fans of abstraction What is the shortest path from 1 to any other node?
  16. 16. Keypoint #2: Abstracting a problem to a problem that has already been solved is even better! You don’t really have to do any work! INTERNET!!! “[OSPF] computes the shortest path tree for each route using a method based on Dijkstra's algorithm, a shortest path first algorithm.”
  17. 17. Keypoint #3 3. There’s no such thing as a dumb problem Problem: Given a spatula and a dish of pancakes (say 6 for now), how would you flip the pancakes such that the pancakes become sorted with the largest pancake at the bottom and smallest at the top? How many steps would it require? FLIP Initial State: GOAL Image source: http://sfist.com/attachments/SFist_Brock/pancakes.jpg
  18. 18. Someone familiar: SORTING PANCAKES == SORTING BY PREFIX REVERSAL Bill Gates & Christos Papadimitriou, Bounds For Sorting By Prefix Reversal. Discrete Mathematics, vol 27, pp 47-57, 1979. We referred to bounds as “Costs”
  19. 19. Key Points: 1. Being able to abstract a problem to something less complex, or more familiar, will make the problem easier! 2. Abstracting a problem to a problem that has already been solved is even better! 3. There’s no such thing as a dumb problem. 4. Be creative and have fun with problems. You have the ability to create an entire world at your fingertips!
  20. 20. -THANK YOU- New title proposal: The best programmers I’ve meet knew how to ABSTRACT PROBLEMS pretty d*mn well “The hardest part of solving a problem is to completely understand it to a point where you can see it from many different perspectives and abstractions” -A very wise T.A. Thank you, -Tony Tran @quicksorte r P.S. My gf will probably be reading this, so the story at the beginning didn’t really happen 0-=) But really, it didn’t =)

×