{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

6111-05-pebbles

# 6111-05-pebbles - Possible Questions to Add to Notes 1 For...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Possible Questions to Add to Notes 1. For many computational problems there is a trade off between the time and the amount of memory needed. There are algorithms that use minimal time but lots of memory and algorithms that use minimal memory but lots of time. One way of modeling this is by a game of pebbling the nodes of a directed acyclic graph (DAG). Each node represents a value that needs to be computed. Having a pebble on a node represents the fact that that value is stored in memory. Note the game has one pebble for each of the memory registers that is available to the algorithm. Pebbles can be removed from a node and placed else where. This corresponds to replacing the value in a register with a newly computed value. However, there is a restriction. If there are edges from each of the nodes In ( v ) = { u 1 , u 2 , . . . , u d } to v , then there needs to be a pebble on these nodes u 1 , u 2 , . . . , u d before you can put a pebble on v . This is modeling the fact that you need the values associated with u 1 , u 2 , . . . , u d in order to be able to compute the value associated with v . In contrast, a pebbles can be placed at any time on a leaf of the DAG because these nodes have no incoming edges. These correspond to the easy to compute values. The input to the pebbling problem specifies a DAG and one of its nodes. The goal is to place a pebble on this node. u 1 u 2 2 u 1 u childeren and Have pebbles on both can place pebble on parent v. v d=2 Get a pebble to the top. You will be required to solve the problem corresponding to pebbling the following DAG. The DAG in consideration will have a rectangle of nodes w wide and h high. Here h much smaller than w , but w is much smaller than 2 h . For each node v (not on the bottom row), there will be d nodes In ( v ) = { u 1 , u 2 , . . . , u d } on the previous row with directed edges to v . Here, d is some small value. You are to write both a iterative and a recursive algorithm for this problem. (a) Iterative: i. Describe an extremely simple iterative algorithm that puts a pebble on the specified node as quickly as possible. The algorithm may use as many pebbles (memory) as needed, but does not redo any work. Being an iterative algorithm, what is the algorithm’s loop invariant? • Answer: This algorithm starts by placing a pebble on each of the nodes on the bottom row. This can be done because each such node has in-degree zero. The loop invariant is that after r iterations, there is a pebble on each of the nodes on the r th row from the bottom. The step of the next iteration is to place pebble on each of the nodes on the r +1 st row from the bottom. This can be done because each such node v has pebbles on all of its in-neighbors In ( v ) = { u 1 , u 2 , . . . , u d } on the previous row. The step ends by removing the pebbles from the r th row so that they can be reused. Note that progress has been made while maintaining the loop invariant. The exit condition is when r = h at which time the task of placing a pebble on the top row has been accomplished.which time the task of placing a pebble on the top row has been accomplished....
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

6111-05-pebbles - Possible Questions to Add to Notes 1 For...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online