Description
1. (10 pts) Let G = (V; E) be a graph with an edgeweight function w, and let the tree

E be a minimum spanning tree on G. Now, suppose that we modify G slightly by decreasing the weight of exactly one of the edges in (x; y) 2 T in order to produce a new graph G^{0}. Here, you will prove that the original tree T is still a minimum spanning tree for the modi ed graph G^{0}.
To get started, let k be a positive number and de ne the weight function w^{0} as

w(x; y)
k if (u; v) = (x; y)
:
w^{0}(u; v) =
w(u; v)
if (u; v) 6= (x; y)
Now, prove that the tree T is a minimum spanning tree for G^{0}, whose edge weights are given by w^{0}.

(20 pts) Professor Snape gives you the following unweighted graph and asks you to construct a weight function w on the edges, using positive integer weights only, such that the following conditions are true regarding minimum spanning trees and singlesource shortest path trees:
The MST is distinct from any of the seven SSSP trees.
The order in which Jarn k/Prim’s algorithm adds the safe edges is di erent from the order in which Kruskal’s algorithm adds them.
Boruvka’s algorithm takes at least two rounds to construct the MST.
Justify your solution by (i) giving the edges weights, (ii) showing the corresponding MST and all the SSSP trees, and (iii) giving the order in which edges are added by each of the three algorithms. (For Boruvka’s algorithm, be sure to denote which edges are added simultaneously in a single round.)
b e
a d f
c g
1
CSCI 3104 
Profs. Clauset & Grochow 
Problem Set 9 
, CUBoulder 

(10 pts extra credit) Crabbe and Goyle think they have come up with a way to get rich by playing the foreign exchange markets in the wizarding world. Their idea is to exploit these exchange rates in order to transform one unit of British wizarding money into more than one unit of British wizarding money, through a sequence of money exchanges. For instance, suppose 1 British wizarding penny buys 0.82 French wizarding pennies, 1 French wizarding penny buys 129.7 Russian wizarding pennies, and nally 1 Russian wizarding penny buys 0.0008 British wizarding pennies. By converting these coins, Crabbe and Goyle think they could start with 1 British wizarding penny and buy 0:82 129:7 12 0:0008 1:02 British wizarding pennies, thereby making a 2% pro t! The problem is that those goblins at Gringots charge a transaction cost for each exchange.
Suppose that Crabbe and Goyle start with knowledge of n wizard monies c_{1}; c_{2}; : : : ; c_{n}
and an n n table R of exchange rates, such that one unit of wizard money c_{i} buys R[i; j] units of wizard money c_{j} . A traditional arbitrage opportunity is thus a cycle in the induced graph such that the product of the edge weights is greater than unity.
That is, a sequence of currencies hc_{i}_{1} ; c_{i}_{2} ; : : : ; c_{i}_{k} i such that R[i_{1}; i_{2}] R[i_{2}; i_{3}] R[i_{k} _{1}; i_{k}] R[i_{k}; i_{1}] > 1. Each transaction, however, must pay Gringots a fraction of the total transaction value, e.g., = 0:01 for a 1% rate.


When given R and , give an e cient algorithm that can determine if an arbitrage opportunity exists. Analyze the running time of your algorithm.

Hermione’s hint: It is possible to solve this problem in O(n^{3}). Recall that BellmanFord can be used to detect negativeweight cycles in a graph.


For an arbitrary R, explain how varying changes the set of arbitrage opportunities that exist and that your algorithm might identify.


(40 pts) Bidirectional breadth rst search is a variant of standard BFS for nding a shortest path between two vertices s; t 2 V (G). The idea is to run two breadth rst searches simultaneously, one starting from s and one starting from t, and stop when they \meet in the middle” (that is, whenever a vertex is encountered by both searches). \Simultaneously” here doesn’t assume you have multiple processors at your disposal; it’s enough to alternate iterations of the searches: one iteration of the loop for the BFS that started at s and one iteration of the loop for the BFS that started at t.
As we’ll see, although the worstcase running time of BFS and Bidirectional BFS are asymptotically the same, in practice Bidirectional BFS often performs signi cantly better.
Throughout this problem, all graphs are unweighted, undirected, simple graphs.
2
CSCI 3104 
Profs. Clauset & Grochow 
Problem Set 9 
, CUBoulder 

Give examples to show that, in the worst case, the asymptotic running time of bidirectional BFS is the same as that of ordinary BFS. Note that because we are asking for asymptotic running time, you actually need to provide an in nite family of examples (G_{n}; s_{n}; t_{n}) such that s_{n}; t_{n} 2 V (G_{n}), the asymptotic running time of BFS and bidirectional BFS are the same on inputs (G_{n}; s_{n}; t_{n}), and jV (G_{n})j ! 1 as n ! 1.

Recall that in ordinary BFS we used a state array (see Lecture Notes 8) to keep track of which nodes had been visited before. In bidirectional BFS we’ll need two state arrays, one for the BFS from s and one for the BFS from t. Why? Give an example to show what can go wrong if there’s only one state array. In particular, give a graph G and two vertices s; t such that some run of a bidirectional BFS says there is no path from s to t when in fact there is one.

Implement from scratch a function BFS(G,s,t) that performs an ordinary BFS in the (unweighted, directed) graph G to nd a shortest path from s to t. Assume the graph is given as an adjacency list; for the list of neighbors of each vertex, you may use any data structure you like (including those provided in standard language libraries). Have your function return a pair (d; k), where d is the distance from s to t (1 if there is no s to t path), and k is the number of nodes popped o the queue during the entire run of the algorithm.

Implement from scratch a function BidirectionalBFS(G,s,t) that takes in a(n unweighted, directed) graph G, and two of its vertices s; t, and performs a bidirectional BFS. As with the previous function, this function should return a pair (d; k) where d is the distance from s to t (1 if there is no path from s to t) and k is the number of vertices popped o of both queues during the entire run of the algorithm.

For each of the following families of graphs G_{n}, write code to execute BFS and BidirectionalBFS on these graphs, and produce the following output:
In text, the pairs (n; d_{1}; k_{1}; d_{2}; k_{2}) where n is the index of the graph, (d_{1}; k_{1}) is the output of BFS and (d_{2}; k_{2}) is the output of BidirectionalBFS.
a plot with n on the xaxis, k on the yaxis, and with two line charts, one for the values of k_{1} and one for the values of k_{2}:

Grids. G_{n} is an n n grid, where each vertex is connected to its neighbors in the four cardinal directions (N,S,E,W). Vertices on the boundary of the grid will only have 3 neighbors, and corners will only have 2 neighbors. Let s_{n} be the midpoint of one edge of the grid, and t_{n} the midpoint of the opposite edge. For example, for n = 3 we have:
3
CSCI 3104 
Profs. Clauset & Grochow 
Problem Set 9 
, CUBoulder 
s_{3} t_{3}
(When n is even s_{n} and t_{n} can be either \midpoint,” since there are two.) Produce output for n = 3; 4; 5; : : : ; 20.

Trees. G_{n} is a complete binary tree of depth n. s_{n} is the root and t_{n} is any leaf. Produce output for n = 3; 4; 5; : : : ; 15. For example, for n = 3 we have:
^{s}3
t_{3}

Random graphs. G_{n} is a graph on n vertices constructed as follows. For each pair of of vertices (i; j), get a random boolean value; if it is true, include the edge (i; j), otherwise do not. Let s_{n} be vertex 1 and t_{n} be vertex 2 (food for thought: why does it not matter, on average, which vertices we take s; t to be?) For each n, produce 50 such random graphs and report just the average values of (d_{1}; k_{1}; d_{2}; k_{2}) over those 50 trials. Produce this output for n = 3; 4; 5; : : : ; 20.
4