Problem Set 4
Problem Set 4
006
Massachusetts Institute of Technology
Instructors: Chinmay Hegde, Piotr Indyk, and Yuan Zhou
March 19 2015
Problem Set 4
Problem Set 4
All parts are due Thursday, April 9 at 11:59PM. Please download the .zip archive for this
problem set. Remember, your goal is to communicate. Full credit will be given only to a correct
solution which is described clearly. Convoluted and obtuse descriptions might receive low marks,
even when they are correct. Also, aim for concise solutions, as it will save you time spent on
write-ups, and also help you conceptualize the key idea of the problem.
Part A
Problem 4-1. [25 points] Graph Paths
In class we saw that given a graph G with n vertices and m edges, we can solve the single-source
shortest path problem using Breadth First Search in O(n + m) time. In this problem, we study
several variants where you are given an origin vertex s and a destination vertex t and you are asked
to compute a specific path between them. In all cases, the graph G will be undirected and will be
represented using an adjacency list.
You are asked to come up with an algorithm for each of the cases below and briefly argue about
its correctness and runtime. Your algorithms should run in O(n + m) with respect to the original
graph G. Each of the following subparts is an independent problem.
(a) [3 points] Some of the edges of G given by a set EA E require 2 units of time to
cross while the rest of the edges require only 1. Compute the path between s and t
that minimizes the time to travel.
(b) [8 points] For a given set VB V of vertices of G, we can teleport directly between
any two points in VB in 1 unit of time even if there is no edge between them. Compute
the path between s and t that minimizes the time to travel. Note that s or t might not
be in the given set VB .
(c) [10 points] Some of the edges of G given by a set EC E require 0 time to cross
while the rest require 1 unit of time. Compute the path between s and t that minimizes
the time to travel.
(d) [4 points] Some of the edges of G given by a set ED E are dangerous. Compute
a path between s and t that minimizes the number of dangerous edges visited.
Problem Set 4
Problem Set 4
1
2
3
For each part, also prove the correctness and analyze the running time of your algorithm.
(a) [5 points] Describe an algorithm to compute the minimum number of moves required
to move from point A to a point B, while visiting at least 1 of the marked squares
along the way. Your algorithm should run in O(n2 ).
(b) [8 points] Describe an algorithm to compute the minimum number of moves required
to move from point A to a point B, while visiting at least 2 of the marked squares
along the way. Your algorithm should run in O(n2 k).
(c) [7 points] Describe an algorithm to compute the minimum number of moves required
to move from point A to a point B, while visiting all of the marked squares along the
way. Your algorithm should run in O(n2 2k ).
Problem Set 4
Part B
Problem 4-4. [40 points] k-Wizard Tournament
Dumbledore: Your attention please. Id like to say a few words. Eternal Glory. That is what awaits
the Student who wins the k-wizard Tournament. Soon we must all face the choice between what is
fast and what is easy. As from this moment, The k-wizard Tournament has begun!
This year, MIT has been chosen to host the k-wizard Tournament. In this tournament, k students
are chosen to participate and try to win the k-wizard cup. It is possible for multiple students to
win the cup. The final task in this tournament is for the students to navigate through the k-wizard
maze to get to the k-wizard cup within T time steps. However unlike a regular maze, the walls in
a k-wizard maze keep changing.
You are given an unbounded maze divided into a grid of squares. All k students start from k
different starting locations s0 , s1 , . . . , sk1 on the maze respectively. Every time step, a student can
choose to stay on the same square or move one square in either of the four directions. However, a
student cannot move into a square which has a wall on it, or will have a wall on it in the next time
step. Multiple students can occupy the same square. A student wins if she/he is able to reach to
the k-wizard cup at location d in T time steps.
(a) [40 points] You need to implement the function get winners(is wall,s,d,T).
This function takes in the following parameters:
is wall(x,y,t): Returns True if there is a wall at the square (x, y) at time t,
otherwise returns False. Note that this is a function.
s: A list of tuples [(x0 , y0 ), (x1 , y1 ), . . ., (xk1 , yk1 )] where (xi , yi )
represents the starting location of the ith student. There will never be a wall on any of
these locations.
d: A tuple (xd , yd ) representing the location of the cup. There will never be a
wall on this location.
T: An integer representing the time within which students must reach the cup in order
to win.
This function should return a list of integers between 0 to k 1 representing the
students who win the cup. If there are no winners, the function should return an
empty list.
Problem Set 4
Example:
In the above maze, there are two students 0 and 1. The star represents the location of the cup. Note
that in this specific example, the walls are not moving.
If you call get winner with T = 3, then it should return an empty list since none of them can
reach the cup in 3 time steps.
If you call get winner with T = 4, then it should return [1] since only student 1 can
reach the cup in 4 time steps.
If you call get winner with T = 5, then it should return [0, 1] since both the students
can reach the cup in 5 time steps.