How To Think Like A Computer Scientist

Download Report

Transcript How To Think Like A Computer Scientist

The Pebble Game
Geri Grolinger
York University
The Pebble Game
• One player game, played on a DAG
• Used for studying time-space
trade-off
Formalization:
• Directed acyclic graph
• Bounded in-degree
Output nodes
Nodes
Input nodes
Three main rules:
1. A pebble can be placed
on any input node
2. A pebble can be placed on a node v
if all predecessors of the node v are
marked with pebbles
3. A pebble can be removed from a
node at any time
Note:
a pebble removed from the graph can be ‘reused’
The Goal:
to place a pebble on some
previously distinguished node
f while minimizing the number
of pebbles used
f
A move:
placing or removing one of the
pebbles
according to the three given rules
Strategy:
sequence of legal moves which ends in
pebbling the distinguished node f
Example 1
70
60
50
30
10
40
20
7 moves and 7 pebbles
Example 2
70
60
50
30
10
40
20
11 moves and 3 pebbles
Interpretation:
output
nodes
nodes
1. A pebble can be placed
on any input node ~ LOAD
input nodes
2. A pebble can be placed on
a node v if all predecessors of the node
v are marked with pebbles ~ COMPUTE
3. A pebble can be removed form a
node at any time ~ DELETE
• Use as few pebbles as possible ~ # REGISERS
• Use as few moves as possible ~ TIME
In general:
How many pebbles
are required to pebble a graph
with n nodes?
Pyramid graph Pk:
Pyramid graph Pk:
Fact 1:
Every pebbling strategy for Pk (k > 1)
must use AT LEAST k + 1 pebbles.
That is Ω( √ n ) pebbles
expressed in number of edges n.
Pyramid graph Pk:
k=5
We need
at least:
k+1=6
Pyramid graph Pk:
Let’s consider
having
k = 5 pebbles
Arbitrary graph with restricted
in-degree (d =2):
Fact 2:
Number of pebbles needed to pebble
a graph of in-degree 2 is O(n/log n)
(n = # nodes in the graph).
Arbitrary graph with restricted
in-degree (d =2):
O(n/log n)
Proof:
• Recursive pebbling strategy
• Cases
• Recursions for each case
• Solutions:
P(n) ≤ cn / log n = O(n/log n)
References:
1. Gems of theoretical computer science
U. Schöning, R. J. Pruim
2. Asymptotically Tight Bounds on Time-Space
Trade-offs in a Pebble Game
T. Lengauer, R. E. Tarjan
3. Theoretical Models 2002/03
P. van Emde Boas
Thank you for your attention 
Questions ?