Upload
melvin-zhang
View
654
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Slides for a talk given at NUS Hacker's Friday Hacks held on 20th Jan 2012
Citation preview
Becoming a BetterProblem Solver:A CS Perspective
Melvin Zhangmelvinzhang.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 tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
Polya’s Mouse
Polya’s Mouse
A good problem solverdoesn’t give up easily, butdon’t keep banging yourhead on the same part ofthe wall.
The key is to vary eachattempt.
References
References
What is problem solving?
Problem solving is the process of tacklingproblems in a systematic and rational way.
Steps in problem solving
Understandingthe problem
Devising a plan
Carrying outthe plan
Looking back
Outline
What is problem solving?
Strategies and tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
Strategies, tactics and tools
StrategiesGeneral approaches and psychological hints forstarting and pursuing problems.
TacticsDiverse methods that work in many differentsettings.
ToolsNarrowly focused techniques and ”tricks” forspecific situations.
Outline
What is problem solving?
Strategies and tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
Strategy 1. Get your hands dirty
Example: Generating Gray codesNamed after Frank Gray, a researcher from BellLabs. Refers to a special type of binary code inwhich adjacent codes different at only one position.
3-bit binary code000001010011100101110111
Example: Generating Gray codes
1-bit01
2-bit00011110
3-bit000001011010110111101100
Applications of Gray codes
Figure: Rotary encoder for angle-measuring devices
I Used in position encoder (see figure).
I Labelling the axis of Karnaugh maps.
I Designing error correcting codes.
Strategy 2. Restate the problem
The problem as it is stated may not have an obvioussolution. Try to restate the problem in a differentway.
Find the Inverse
Original Given a set of object, find an objectsatisfying some property P .
Inverse Find all of the objects which does NOTsatisfy P .
Example: Invitation
You want to invite thelargest group of friends,so that each person knowat least k others at theparty.
Invitation
Direct approach
1. For each subset of friends, check if everyoneknows at least k others.
2. Return the largest set of friends.
Looking backWorks but there are potentially 2n subsets to check,where n is the number of friends.
Invitation
Find the InverseInstead of finding the largest group to invite, findthe smallest group that is left out.
ObservationA person with less than k friends must be left out.
Strategy 3. Wishful thinking
Make the problem simpler by removing the sourceof 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 allrectangles. There are
(n2
)×(n2
)≈ n4 rectangles.
Example: Largest rectangle
2D seems to be difficult, how about 1D?
There are(n2
)segments in a row, but we can find
the longest white segment using a single scan of therow. What is that so?
Example: Next Gray code
Given an n-bit Gray code, find the next code.
3-bit Gray code000001011010110111101100
Example: Next Gray code
Gray code is tough! What if we worked in binary?
Binary code
101
110
Gray code
111
101
Outline
What is problem solving?
Strategies and tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
Making progress
Record your progressAny form of progress is good, record your workingsand keep track of interesting ideas/observations.
Sometimes, you mighthave 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 whichare extreme.
I Tallest/shortest
I Leftmost/rightmost
I Largest/smallest
Example: Activity selection
Each bar represents an activity with a particularstart and end time. Find the largest set of activitieswith no overlap.
Example: Activity selection
An intuitive approach is to repeatedly pick theleftmost 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 code3-bit Gray code 3-bit binary code
000 000001 001011 010010 011110 100111 101101 110100 111
Some observations:I The leftmost column is always the same.I After a column of ones, the order flips
(reflection).
Example: Gray code to binary code
3-bit Gray code000001011010110111101100
Order 0 1 01 0 1
Gray code 1 1 0Binary code 1 0 0
Tactic 3. Space-time tradeoff
Trading space for time: lookup tables, cachingTrading time for space: recalculation
Example: Computing segment sums
Given an array A of integers, compute the sum ofany segment A[i , j ] efficiently.
6 4 -3 0 5 1 8 7
For example,
I A[1, 3] = 6 + 4 + −3 = 7
I 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 onlysegments of the form A[1, j ]?
Space-time tradeoff Sums for A[1, j ] can beprecomputed and stored in a anotherarray P
A 6 4 -3 0 5 1 8 7P 6 10 7 7 12 13 24 31
Example: Computing segment sums
A 6 4 -3 0 5 1 8 7P 6 10 7 7 12 13 24 31
ObservationThe sum for A[i , j ] can be computed asP[j ] − P[i ] + A[i ].
Example: Computing segment sums
Looking back
I What is special about sum?
I Does this work with max/min? If not, can theidea be adapted?
Outline
What is problem solving?
Strategies and tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
Strategies and tactics
Strategies
1. Get your hands dirty
2. Restate the problem
3. Wishful thinking
Tactics
1. Extremal principle
2. Exploit symmetry
3. Space-time tradeoff
If there is a problem you can’t solve, thenthere is an easier problem you can solve:find it.
George Polya
Outline
What is problem solving?
Strategies and tacticsGetting started (Strategies)Making progress (Tactics)
Summary
What I’m working on
developer.hoiio.com
magarena.googlecode.com