slides - Computer Science Department

Download Report

Transcript slides - Computer Science Department

Problems as Puzzles
William Gasarch, Evan Golub
Department of Computer Science
University of Maryland
Why puzzles?
Before you can begin to code a program to solve a
problem, you need to figure out how the problem
can be solved.
Once you know what you want to build, you need to
design a plan to implement the solution.
You need to devise tests to determine whether your
implementation is correct. To do this, you often
need to play the adversary to your own ideas.
These “puzzle” stages are critical components in the
life cycle of an application.
Take real world problems and turn them into math
and/or algorithm problems.
William Gasarch, Evan Golub - UMD
2
The Dr. Ecco Series by Dennis Shasha
•
•
•
•
•
The Puzzling Adventures of Dr. Ecco
Dr. Ecco: Mathematical Detective
Dr. Ecco's Cyberpuzzles
Puzzling Adventures
The Puzzler's Elusion
…and many other books of puzzles…
William Gasarch, Evan Golub - UMD
3
Cake Cutting
You have a regular round cake with icing on
top. You want to cut it into 16 equal pieces
using only 4 straight cuts.
How would you do it?
William Gasarch, Evan Golub - UMD
4
Cake Cutting
You have a regular round cake with icing on
top. You want to cut it into 16 equal pieces
using only 4 straight cuts.
Lessons:
• Lateral Thinking
• Powers of 2
William Gasarch, Evan Golub - UMD
5
Cake Cutting
You have a regular round cake with icing on
top. You want to cut it into 16 equal pieces
using only 4 straight cuts.
Questions:
• How long do you give students to work on it?
• What if a student wants to keep working on it
until they figure it out?
• What if they want to ask questions as they
are working on it?
William Gasarch, Evan Golub - UMD
6
Single-elimination Tournament
Assume you have a problem in which there are
multiple candidates or players or ideas that
need to compete against each other, but that
one-on-one competition is the only direct test
available to you, and once someone/thing
loses a round, it’s out.
William Gasarch, Evan Golub - UMD
7
Single-elimination Tournament
Candidate A and Candidate B each have 40%
of the population strongly on their side and
totally opposed to the other of the two
candidates.
Candidate C has 20% of the population who
would vote for them.
Everyone must vote in every election.
• How can Candidate C win?
William Gasarch, Evan Golub - UMD
8
Single-elimination Tournament
Candidate A and Candidate B each have 40%
of the population strongly on their side and
totally opposed to the other of the two
candidates.
Candidate C has 20% of the population who
would vote for them.
Everyone must vote in every election.
• How can Candidate C win?
• Is there a way for Candidate C lose?
William Gasarch, Evan Golub - UMD
9
Single-elimination Tournament
There are four proposals. People have ranked the
proposals differently:
17% of the people like C better than A, A better that D and
D better than B
32% of the people like A better than B, B better that D and
D better than C
34% of the people like D better than B, B better that C and
C better than A
17% of the people like B better than A, A better that C and
C better than D
• In what order would you hold the elections to make
sure that Choice C wins?
___TRY
William Gasarch, Evan Golub - UMD
IT!
10
Single-elimination Tournament
There are four proposals. People have ranked the
proposals differently:
17% of the people like C better than A, A better that D and
D better than B
32% of the people like A better than B, B better that D and
D better than C
34% of the people like D better than B, B better that C and
C better than A
17% of the people like B better than A, A better that C and
C better than D
• In what order would you hold the elections to make
sure that Choice C wins?
• For each of the four choices, does there exist an
ordering that will allow the choice to win?
William Gasarch, Evan Golub - UMD
11
Single-elimination Tournament
There are eight tennis players that need to be
ranked. You may assume that if A beats B in
one match and if B beats C in another match,
that if A were to play C the outcome is
already known; A will beat C.
• Assuming there is one tennis court available,
and that a game takes an hour, can you rank
all of the players in fewer than twenty hours?
• How many hours would it take if you instead
had four courts available?
William Gasarch, Evan Golub - UMD
12
Single-elimination Tournament
Assume you have a problem in which there are
multiple candidates or players or ideas that
need to compete against each other, but that
one-on-one competition is the only direct test
available to you…
Lessons:
•
•
•
•
•
Game/Decision Trees
Combinatorics
Working Backwards From a Goal
Sorting
Parallelism
William Gasarch, Evan Golub - UMD
13
Single-elimination Tournament
Assume you have a problem in which there are
multiple candidates or players or ideas that
need to compete against each other, but that
one-on-one competition is the only direct test
available to you…
Questions:
• How many different problems do you do within an
area, even if the solutions are different?
• In how many increasingly levels of challenge do
you present questions?
William Gasarch, Evan Golub - UMD
14
Clock Gourds
A gourd is a fruit. Let’s say that if you poke one hole
in it then the water it contains will drain in exactly 11
minutes. If you poke two holes in it then the water
will drain in exactly 5 minutes. Using these facts,
can you time 1 minute?
William Gasarch, Evan Golub - UMD
15
Clock Gourds
A gourd is a fruit. Let’s say that if you poke one hole
in it then the water it contains will drain in exactly 11
minutes. If you poke two holes in it then the water
will drain in exactly 5 minutes. Using these facts,
can you time 1 minute?
Generalize: Let a1,...,an be positive integers.
Assume you have gourds that drain in a1 minutes,
a2 minutes, ..., an minutes.
Which “times” can you measure?
William Gasarch, Evan Golub - UMD
16
Clock Gourds
A gourd is a fruit. Let’s say that if you poke one hole
in it then the water it contains will drain in exactly 11
minutes. If you poke two holes in it then the water
will drain in exactly 5 minutes. Using these facts,
can you time 1 minute?
Generalize: Let a1,...,an be positive integers.
Assume you have gourds that drain in a1 minutes,
a2 minutes, ..., an minutes.
Which “times” can you measure?
Lesson: Model problems as graphs.
William Gasarch, Evan Golub - UMD
17
Zoranic Monopoles
The book presents a problem where there are 52
compounds, numbered from 1..52 (and later increases
this to 65 compounds).
A box is allowed to contain any number of the compounds
but if there are three compounds X, Y, Z in the box such
that X+Y=Z, then the box explodes!
How many boxes required to pack up all of the
compounds WITHOUT having anything blow up?
Let’s think of it as compounds numbered from 1…N and
consider for how large an N can we solve this here
today.
TRY IT!
William Gasarch, Evan Golub - UMD
18
Zoranic Monopoles
The book presents a problem where there are 52
compounds, numbered from 1..52 (and later increases
this to 65 compounds).
A box is allowed to contain any number of the compounds
but if there are three compounds X, Y, Z in the box
such that X+Y=Z, then the box explodes!
How many boxes required to pack up all of the
compounds WITHOUT having anything blow up?
Let’s think of it as compounds numbered from 1…N and
consider for how large an N can we solve this here
today.
Lessons: Greedy algorithms, Open problems
William Gasarch, Evan Golub - UMD
19
Hovertanks in Battle
Assume there are 25 hills to which a tank can go
(number them 0, 1, 2, …, 24).
For each hill we can only shoot at certain hills (e.g.,
from hill 0 we can only shoot hills 1, 2, 3, 7).
We have 10 tanks available.
Where should you put them so that every hill is either:
– occupied
– can be shot it by a hill that is occupied
Generalize: A graph is a set of vertices and lines
(called edges) between some of them. Given a
graph and a number k, can you pick out k vertices
so that every vertex is either picked or adjacent to
one that is picked?
William Gasarch, Evan Golub - UMD
20
Hovertanks in Battle
Assume there are 25 hills to which a tank can go
(number them 0, 1, 2, …, 24).
For each hill we can only shoot at certain hills (e.g.,
from hill 0 we can only shoot hills 1, 2, 3, 7).
We have 10 tanks available.
Where should you put them so that every hill is either:
– occupied
– can be shot it by a hill that is occupied
Lesson:
There are problems that currently take a long time to
solve perfectly, but a greedy algorithm might give a
good answer in good time.
William Gasarch, Evan Golub - UMD
21
Lasers on Utopia Basin
There are stations on Mars. We need to be able to fly (using
Laser Shuttles) from one to the other. We will set up routes
from certain pairs of cities but we want to make sure that
there are never any crashes!
If the path from (say) A to B crosses the path from C to D we
will never have A--B and C--D as routes.
We want to know what is the max number of routes we can set
up without two routes crossing.
Generalize: Given any n points in the plane, how many straight
lines can you put between pairs of them?
Lesson: This is the “maximum number of edges in a Euclidean
planar graph” problem!
William Gasarch, Evan Golub - UMD
22
Untangling the Rosetta Web
You are given two graphs. One uses the labels fig,
prune, grapefruit, apricot, currant, pineapple, date,
raisin, coconut. The other uses nine labels in an
alien language.
We know the two graphs are the same.
You need to figure out which alien words to use to ask
for the fruit that you know you like
Lesson:
This is a classic “graph isomorphism” problem.
A follow-up question could be “What if there is not a
unique solution?”
William Gasarch, Evan Golub - UMD
23
The Richest of Them All
There are 20 hecto-millionaires (over 100 million
dollars) in a club.
They all have between 100 million dollars and 10
billion dollars.
They want to know what the least amount of money is
that someone in the club has and what the most
amount of money that someone in the club has.
But they DO NOT want to know who those “poorest”
and “richest” people ARE.
They can only communicate by calling each other
one-on-one and exchanging information.
Can they accomplish this? TRY IT! (at home)
William Gasarch, Evan Golub - UMD
24
Puzzles and games can be great
sources of problems in
computational thinking which can
engage and motivate students…