SlideShare a Scribd company logo
Becoming a Better
    Problem Solver:
    A CS Perspective

             Melvin Zhang
           melvinzhang.net
      http://www.slideshare.net/melvinzhang/
becoming-a-better-problem-solver-a-cs-perspective


            January 20, 2012
Becoming a Better Problem Solver:
A CS Perspective
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
P´lya’s Mouse
 o
P´lya’s Mouse
 o

                A good problem solver
                doesn’t give up easily, but
                don’t keep banging your
                head on the same part of
                the wall.

                The key is to vary each
                attempt.
References
References
What is problem solving?



  Problem solving is the process of tackling
  problems in a systematic and rational way.
Steps in problem solving
                    Understanding
                     the problem




     Looking back                  Devising a plan




                    Carrying out
                      the plan
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
Strategies, tactics and tools

  Strategies
  General approaches and psychological hints for
  starting and pursuing problems.
  Tactics
  Diverse methods that work in many different
  settings.
  Tools
  Narrowly focused techniques and ”tricks” for
  specific situations.
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
Strategy 1. Get your hands dirty
Example: Generating Gray codes
  Named after Frank Gray, a researcher from Bell
  Labs. Refers to a special type of binary code in
  which adjacent codes different at only one position.

                   3-bit binary code
                          000
                          001
                          010
                          011
                          100
                          101
                          110
                          111
Example: Generating Gray codes

    1-bit         2-bit          3-bit
      0            00            000
      1            01            001
                   11            011
                   10            010
                                 110
                                 111
                                 101
                                 100
Applications of Gray codes




     Figure: Rotary encoder for angle-measuring devices


     Used in position encoder (see figure).
     Labelling the axis of Karnaugh maps.
     Designing error correcting codes.
Strategy 2. Restate the problem

  The problem as it is stated may not have an obvious
  solution. Try to restate the problem in a different
  way.
  Find the Inverse
   Original Given a set of object, find an object
            satisfying some property P.
    Inverse Find all of the objects which does NOT
            satisfy P.
Example: Invitation



                      You want to invite the
                      largest group of friends,
                      so that each person know
                      at least k others at the
                      party.
Invitation

  Direct approach
   1. For each subset of friends, check if everyone
      knows at least k others.
   2. Return the largest set of friends.

  Looking back
  Works but there are potentially 2n subsets to check,
  where n is the number of friends.
Invitation


  Find the Inverse
  Instead of finding the largest group to invite, find
  the smallest group that is left out.
  Observation
  A person with less than k friends must be left out.
Strategy 3. Wishful thinking




  Make the problem simpler by removing the source
  of difficulty!
    1. Identify what makes the problem difficult.
    2. Remove or reduce the difficulty.
Example: Largest rectangle




  Find the largest white rectangle in an n × n grid.
  There is an easy solution which checks all
  rectangles. There are n × n ≈ n4 rectangles.
                          2    2
Example: Largest rectangle


  2D seems to be difficult, how about 1D?




  There are n segments in a row, but we can find
              2
  the longest white segment using a single scan of the
  row. What is that so?
Example: Next Gray code
  Given an n-bit Gray code, find the next code.

                   3-bit Gray code
                         000
                         001
                         011
                         010
                         110
                         111
                         101
                         100
Example: Next Gray code

  Gray code is tough! What if we worked in binary?

          Gray code             Binary code

             111                    101


             101                    110
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
Making progress
  Record your progress
  Any form of progress is good, record your workings
  and keep track of interesting ideas/observations.




                             Sometimes, you might
                             have to sleep on it.
Story of RSA




  Figure: Left to right: Adi Shamir, Ron Rivest, Len Adleman
Tactic 1. Extremal principle


  Given a choice, it is useful to consider items which
  are extreme.
       Tallest/shortest
       Leftmost/rightmost
       Largest/smallest
Example: Activity selection
  Each bar represents an activity with a particular
  start and end time. Find the largest set of activities
  with no overlap.
Example: Activity selection
  An intuitive approach is to repeatedly pick the
  leftmost activity.




     Does this produce the largest set of activities?
Example: Activity selection

  This method may be fooled! Consider the following:
Example: Activity selection

  How would you normally pick among a set of tasks?
  Do the one with the earliest deadline first!
Tactic 2. Exploit symmetry
Example: Gray code to binary code
          3-bit Gray code 3-bit binary code
                000              000
                001              001
                011              010
                010              011
                110              100
                111              101
                101              110
                100              111
  Some observations:
     The leftmost column is always the same.
     After a column of ones, the order flips
     (reflection).
Example: Gray code to binary code

    3-bit Gray code
          000
          001
                        Order     0   1   0
          011
                                  1   0   1
          010
                       Gray code 1    1   0
          110
                      Binary code 1   0   0
          111
          101
          100
Tactic 3. Space-time tradeoff



  Trading space for time: lookup tables, caching
  Trading time for space: recalculation
Example: Computing segment sums

  Given an array A of integers, compute the sum of
  any segment A[i, j] efficiently.

               6 4 -3 0 5 1 8 7

  For example,
       A[1, 3] = 6 + 4 + −3 = 7
       A[3, 7] = −3 + 0 + 5 + 1 + 8 = 11
Example: Computing segment sums

  Wishful thinking Computing for any segment A[i, j]
             is difficult, what if we consider only
             segments of the form A[1, j]?
  Space-time tradeoff Sums for A[1, j] can be
             precomputed and stored in a another
             array P

          A 6 4 -3 0 5 1 8 7
          P 6 10 7 7 12 13 24 31
Example: Computing segment sums


          A 6 4 -3 0 5 1 8 7
          P 6 10 7 7 12 13 24 31

  Observation
  The sum for A[i, j] can be computed as
  P[j] − P[i] + A[i].
Example: Computing segment sums


  Looking back
     What is special about sum?
     Does this work with max/min? If not, can the
     idea be adapted?
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
Strategies and tactics



 Strategies                 Tactics
  1. Get your hands dirty    1. Extremal principle
  2. Restate the problem     2. Exploit symmetry
  3. Wishful thinking        3. Space-time tradeoff
If there is a problem you can’t solve, then
there is an easier problem you can solve:
find it.




                                   George P´lya
                                           o
Outline

  What is problem solving?

  Strategies and tactics
      Getting started (Strategies)
      Making progress (Tactics)

  Summary

  What I’m working on
developer.hoiio.com
magarena.googlecode.com

More Related Content

PPTX
Agent tic tac-toe - an interactive game for computational thinking
PPT
Cmp104 lec 2 number system
PDF
Bitwise
PDF
Midterm sols
PDF
Oth1
PDF
Buacm 3
PDF
Top10- Software Engineering Books
PDF
Algorithms for programmers ideas and source code
Agent tic tac-toe - an interactive game for computational thinking
Cmp104 lec 2 number system
Bitwise
Midterm sols
Oth1
Buacm 3
Top10- Software Engineering Books
Algorithms for programmers ideas and source code

Similar to Becoming a better problem solver: a CS perspective (20)

PDF
Sure interview algorithm-1103
PDF
Sienna 5 decreaseandconquer
PDF
Soal latihan algoritma
PPTX
Chapter 5.pptx
PPT
05 adversarial
PDF
Algorithm chapter 1
PDF
Algorithms
PDF
Algorithm chapter 5
PDF
PDF
CSC 101-CSC 111 - Introduction to Computer Science - Lecture 4.pdf
PPT
L12 complexity
PDF
Algorithms - A Sneak Peek
PPTX
Binary and EC codes
PDF
PDF
From programming to software engineering: ICSE keynote slides available
PDF
Algorithms
PDF
Daa chapter4
PDF
PPTX
Class[1][23ed may] [algorithms]
PDF
ADA complete notes
Sure interview algorithm-1103
Sienna 5 decreaseandconquer
Soal latihan algoritma
Chapter 5.pptx
05 adversarial
Algorithm chapter 1
Algorithms
Algorithm chapter 5
CSC 101-CSC 111 - Introduction to Computer Science - Lecture 4.pdf
L12 complexity
Algorithms - A Sneak Peek
Binary and EC codes
From programming to software engineering: ICSE keynote slides available
Algorithms
Daa chapter4
Class[1][23ed may] [algorithms]
ADA complete notes
Ad

More from Melvin Zhang (19)

PDF
How Alan Turing accidentally invented Software
PDF
Solving the TSP for warehouses
PDF
Optimize all the things with MiniZinc
PDF
AMKSS Career Conference 2018: Software Engineering
PDF
Beating us at our own Games
PDF
Getting started with open source game playing AIs
PDF
Programs that Play better than Us
PDF
Building a Turing Machine emulator to explore Turing's great ideas
PDF
Lessons from Developing an AI to Play Magic: The Gathering
PDF
Functional programming from first principles
PDF
Binary Lambda Calculus and Combinatory Logic
PDF
AMKSS Career Conference 2015: Programming
PDF
Building a state of the art AI to play Magic: The Gathering
PDF
Efficient Selectivity and Backup Operators in Monte-Carlo Tree Search
PDF
Quest for the optimal algorithm
PDF
Playing Games by Throwing Dice
PDF
Ortholog assignment
PDF
Building pipelines with Make
PDF
Opportunities in STEM
How Alan Turing accidentally invented Software
Solving the TSP for warehouses
Optimize all the things with MiniZinc
AMKSS Career Conference 2018: Software Engineering
Beating us at our own Games
Getting started with open source game playing AIs
Programs that Play better than Us
Building a Turing Machine emulator to explore Turing's great ideas
Lessons from Developing an AI to Play Magic: The Gathering
Functional programming from first principles
Binary Lambda Calculus and Combinatory Logic
AMKSS Career Conference 2015: Programming
Building a state of the art AI to play Magic: The Gathering
Efficient Selectivity and Backup Operators in Monte-Carlo Tree Search
Quest for the optimal algorithm
Playing Games by Throwing Dice
Ortholog assignment
Building pipelines with Make
Opportunities in STEM
Ad

Recently uploaded (20)

PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
master seminar digital applications in india
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Lesson notes of climatology university.
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Trump Administration's workforce development strategy
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Microbial diseases, their pathogenesis and prophylaxis
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
master seminar digital applications in india
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Lesson notes of climatology university.
History, Philosophy and sociology of education (1).pptx
Microbial disease of the cardiovascular and lymphatic systems
Chinmaya Tiranga quiz Grand Finale.pdf
Anesthesia in Laparoscopic Surgery in India
Trump Administration's workforce development strategy
UNIT III MENTAL HEALTH NURSING ASSESSMENT

Becoming a better problem solver: a CS perspective

  • 1. Becoming a Better Problem Solver: A CS Perspective Melvin Zhang melvinzhang.net http://www.slideshare.net/melvinzhang/ becoming-a-better-problem-solver-a-cs-perspective January 20, 2012
  • 2. Becoming a Better Problem Solver: A CS Perspective
  • 3. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on
  • 5. P´lya’s Mouse o A good problem solver doesn’t give up easily, but don’t keep banging your head on the same part of the wall. The key is to vary each attempt.
  • 8. What is problem solving? Problem solving is the process of tackling problems in a systematic and rational way.
  • 9. Steps in problem solving Understanding the problem Looking back Devising a plan Carrying out the plan
  • 10. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on
  • 11. Strategies, tactics and tools Strategies General approaches and psychological hints for starting and pursuing problems. Tactics Diverse methods that work in many different settings. Tools Narrowly focused techniques and ”tricks” for specific situations.
  • 12. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on
  • 13. Strategy 1. Get your hands dirty
  • 14. Example: Generating Gray codes Named after Frank Gray, a researcher from Bell Labs. Refers to a special type of binary code in which adjacent codes different at only one position. 3-bit binary code 000 001 010 011 100 101 110 111
  • 15. Example: Generating Gray codes 1-bit 2-bit 3-bit 0 00 000 1 01 001 11 011 10 010 110 111 101 100
  • 16. Applications of Gray codes Figure: Rotary encoder for angle-measuring devices Used in position encoder (see figure). Labelling the axis of Karnaugh maps. Designing error correcting codes.
  • 17. Strategy 2. Restate the problem The problem as it is stated may not have an obvious solution. Try to restate the problem in a different way. Find the Inverse Original Given a set of object, find an object satisfying some property P. Inverse Find all of the objects which does NOT satisfy P.
  • 18. Example: Invitation You want to invite the largest group of friends, so that each person know at least k others at the party.
  • 19. Invitation Direct approach 1. For each subset of friends, check if everyone knows at least k others. 2. Return the largest set of friends. Looking back Works but there are potentially 2n subsets to check, where n is the number of friends.
  • 20. Invitation Find the Inverse Instead of finding the largest group to invite, find the smallest group that is left out. Observation A person with less than k friends must be left out.
  • 21. Strategy 3. Wishful thinking Make the problem simpler by removing the source of difficulty! 1. Identify what makes the problem difficult. 2. Remove or reduce the difficulty.
  • 22. Example: Largest rectangle Find the largest white rectangle in an n × n grid. There is an easy solution which checks all rectangles. There are n × n ≈ n4 rectangles. 2 2
  • 23. Example: Largest rectangle 2D seems to be difficult, how about 1D? There are n segments in a row, but we can find 2 the longest white segment using a single scan of the row. What is that so?
  • 24. Example: Next Gray code Given an n-bit Gray code, find the next code. 3-bit Gray code 000 001 011 010 110 111 101 100
  • 25. Example: Next Gray code Gray code is tough! What if we worked in binary? Gray code Binary code 111 101 101 110
  • 26. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on
  • 27. Making progress Record your progress Any form of progress is good, record your workings and keep track of interesting ideas/observations. Sometimes, you might have to sleep on it.
  • 28. Story of RSA Figure: Left to right: Adi Shamir, Ron Rivest, Len Adleman
  • 29. Tactic 1. Extremal principle Given a choice, it is useful to consider items which are extreme. Tallest/shortest Leftmost/rightmost Largest/smallest
  • 30. Example: Activity selection Each bar represents an activity with a particular start and end time. Find the largest set of activities with no overlap.
  • 31. Example: Activity selection An intuitive approach is to repeatedly pick the leftmost activity. Does this produce the largest set of activities?
  • 32. Example: Activity selection This method may be fooled! Consider the following:
  • 33. Example: Activity selection How would you normally pick among a set of tasks? Do the one with the earliest deadline first!
  • 34. Tactic 2. Exploit symmetry
  • 35. Example: Gray code to binary code 3-bit Gray code 3-bit binary code 000 000 001 001 011 010 010 011 110 100 111 101 101 110 100 111 Some observations: The leftmost column is always the same. After a column of ones, the order flips (reflection).
  • 36. Example: Gray code to binary code 3-bit Gray code 000 001 Order 0 1 0 011 1 0 1 010 Gray code 1 1 0 110 Binary code 1 0 0 111 101 100
  • 37. Tactic 3. Space-time tradeoff Trading space for time: lookup tables, caching Trading time for space: recalculation
  • 38. Example: Computing segment sums Given an array A of integers, compute the sum of any segment A[i, j] efficiently. 6 4 -3 0 5 1 8 7 For example, A[1, 3] = 6 + 4 + −3 = 7 A[3, 7] = −3 + 0 + 5 + 1 + 8 = 11
  • 39. Example: Computing segment sums Wishful thinking Computing for any segment A[i, j] is difficult, what if we consider only segments of the form A[1, j]? Space-time tradeoff Sums for A[1, j] can be precomputed and stored in a another array P A 6 4 -3 0 5 1 8 7 P 6 10 7 7 12 13 24 31
  • 40. Example: Computing segment sums A 6 4 -3 0 5 1 8 7 P 6 10 7 7 12 13 24 31 Observation The sum for A[i, j] can be computed as P[j] − P[i] + A[i].
  • 41. Example: Computing segment sums Looking back What is special about sum? Does this work with max/min? If not, can the idea be adapted?
  • 42. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on
  • 43. Strategies and tactics Strategies Tactics 1. Get your hands dirty 1. Extremal principle 2. Restate the problem 2. Exploit symmetry 3. Wishful thinking 3. Space-time tradeoff
  • 44. If there is a problem you can’t solve, then there is an easier problem you can solve: find it. George P´lya o
  • 45. Outline What is problem solving? Strategies and tactics Getting started (Strategies) Making progress (Tactics) Summary What I’m working on