CS 2 (Winter 2024) Lab 08: Pebbling Game

This lab focuses on using a topological sort to solve a graph problem.

Setup

Register for the lab using grinch: https://grinch.caltech.edu/register and clone the repository as explained in the setup instructions.

Goals and Outcomes

By the end of this lab, you will…

Pebbling Game

Given a DAG \(G\), we define a valid move in the pebbling game as either removing or adding a pebble according to the following rules:

The “easiest” solution to this problem is to just add pebbles and never remove them. But what order should they be added in? This is exactly the topological sort problem from lecture.

public List<Integer> toposort()

Returns a List of ids of PebblingNodes in any valid topological sorted order.

We care about pebbling because it’s a model of a trade-off between space (each pebble represents a memory location) and time (the number of moves represents the time an algorithm takes).

Checking the Results on gitlab