0% found this document useful (0 votes)
69 views5 pages

Problem Set 4

This document provides the details for Problem Set 4 assigned by the instructors of the MIT course 6.006 Introduction to Algorithms. It includes 4 problems to solve: 1) Graph Paths - Find shortest paths in graphs allowing time-varying edge weights and teleportation between some vertices. 2) Task Scheduling - Topologically sort tasks with dependency constraints to find a feasible scheduling order. 3) Knight on a Chessboard - Find minimum moves for a knight to travel between points on a board, visiting marked squares. 4) k-Wizard Tournament - Implement an algorithm to determine the winners of a tournament where k wizards navigate a changing maze to reach the cup within T time steps

Uploaded by

AnthonyLobko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views5 pages

Problem Set 4

This document provides the details for Problem Set 4 assigned by the instructors of the MIT course 6.006 Introduction to Algorithms. It includes 4 problems to solve: 1) Graph Paths - Find shortest paths in graphs allowing time-varying edge weights and teleportation between some vertices. 2) Task Scheduling - Topologically sort tasks with dependency constraints to find a feasible scheduling order. 3) Knight on a Chessboard - Find minimum moves for a knight to travel between points on a board, visiting marked squares. 4) k-Wizard Tournament - Implement an algorithm to determine the winners of a tournament where k wizards navigate a changing maze to reach the cup within T time steps

Uploaded by

AnthonyLobko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction to Algorithms: 6.

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 4-2. [15 points] Task Scheduling


MIT students are usually very busy and have many tasks they need to perform each day. Mark, as
a well organized MIT person, likes to make a list of things which need to be done every morning.
However, several of his daily tasks can only be started after some others have ended, so he needs to
know in which order to perform each task to satisfy all the constraints. You are asked to create an
algorithm to help Mark with his schedule. Consider a list of 11 tasks with the following constraints:
6 should precede 7 and 9, 2 should precede 9, 8 should precede 4, 3 should precede 4, 4 should
precede 11, 11 should precede 1 and 6, 5 should precede 10, 9 should precede 1, 1 should precede
10, and finally 10 should precede 7.
(a) [3 points] Draw a directed graph with states corresponding to the eleven tasks adding
a directed edge between each pair of tasks that one needs to come before the other.
A topological sort of this graph will give a feasible order for scheduling Marks daily
tasks.
(b) [3 points] Emulate DFS on the graph and draw a picture of the resulting forest, plus a
list of the order of events in which you discover and finish each node. Start with node
1 and when you must make a choice, choose the lowest-numbered unvisited node. For
example, if the graph were:
1

Then your output would be:


Discover 1, Discover 2, Finish 2, Discover 3, Discover 4, Finish 4, Finish 3, Finish 1
(c) [3 points] Demonstrate that the order of discover events in your list in part (b) does
not yield a correct order for Marks schedule.
(d) [3 points] Now consider the reverse of the order of finish events. List the steps. Does
this satisfy all the ordering constraints?
(e) [3 points] The key to why this works is that, when performing DFS on an acyclic
directed graph, there are no situations where there is an edge from a node u to another
node v, but u finishes before v finishes. Explain why no such situation arises.

Problem Set 4

Problem 4-3. [20 points] Knight on a Chessboard


You are given an n n chessboard where k blocks have been marked. For this task you are asked
to move a knight from position A at (xA , yA ) to position B at (xB , yB ). Consider a knight at
position (x, y). In the next step, it can visit one of: (x + 1, y + 2), (x + 1, y 2), (x 1, y + 2),
(x 1, y 2), (x + 2, y + 1), (x + 2, y 1), (x 2, y + 1), or (x 2, y 1), assuming that each
of those coordinates actually lies within the bounds of the board. The following figure shows a
sample input configuration where n = 4 and k = 2.
1

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.

You might also like