Professional Documents
Culture Documents
Problem Solver:
A CS Perspective
Summary
Pólya’s Mouse
Pólya’s Mouse
Carrying out
the plan
Outline
Summary
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
Summary
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.
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
111 101
101 110
Outline
Summary
Making progress
Record your progress
Any form of progress is good, record your workings
and keep track of interesting ideas/observations.
I Leftmost/rightmost
I 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.
(reflection).
Example: Gray code to binary code
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
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
I What is special about sum?
I Does this work with max/min? If not, can the
idea be adapted?
Outline
Summary
Strategies and tactics
Strategies Tactics
1. Get your hands dirty 1. Extremal principle
2. Restate the problem 2. Symmetry
3. Wishful thinking 3. Space/time trade-off
Duality of Problem and Solution
J. Krishnamurti