# Weighted Graph Algorithms

### Simulating Graph Algorithms

8.1. For the graphs in Problem 7-1:
(a) Draw the spanning forest after every iteration of the main loop in Kruskal’s algorithm.
(b) Draw the spanning forest after every iteration of the main loop in Prim’s algorithm.
(c) Find the shortest-path spanning tree rooted in $A$ .
(d) Compute the maximum flow from $A$ to $H$ .

### Minimum Spanning Tree

8.2. Is the path between two vertices in a minimum spanning tree necessarily a shortest path between the two vertices in the full graph? Give a proof or a counterexample.

8.3. Assume that all edges in the graph have distinct edge weights (i.e., no pair of edges have the same weight). Is the path between a pair of vertices in a minimum spanning tree necessarily a shortest path between the two vertices in the full graph? Give a proof or a counterexample.

8.4. Can Prim’s and Kruskal’s algorithms yield different minimum spanning trees? Explain why or why not.

8.5. Does either Prim’s or Kruskal’s algorithm work if there are negative edge weights? Explain why or why not.

8.6. (a) Assume that all edges in the graph have distinct edge weights (i.e., no pair of edges have the same weight). Is the minimum spanning tree of this graph unique? Give a proof or a counterexample.
(b) Again, assume that all edges in the graph have distinct edge weights (i.e. no pair of edges have the same weight). Is the shortest-path spanning tree of this graph unique? Give a proof or a counterexample.

8.7. Suppose we are given the minimum spanning tree $T$ of a given graph $G$ (with $n$ vertices and $m$ edges) and a new edge $e=(u,v)$ of weight $w$ that we will add to $G$ . Give an efficient algorithm to find the minimum spanning tree of the graph $G+e$ . Your algorithm should run in $O(n)$ time to receive full credit.

8.8. (a) Let $T$ be a minimum spanning tree of a weighted graph $G$ . Construct a new graph $G'$ by adding a weight of $k$ to every edge of $G$ . Do the edges of $T$ form a minimum spanning tree of $G'$ ? Prove the statement or give a counterexample.
(b) Let $P={s,...,t}$ describe a shortest path between vertices $s$ and $t$ of a weighted graph $G$ . Construct a new graph $G'$ by adding a weight of $k$ to every edge of $G$ . Does $P$ describe a shortest path from $s$ to $t$ in $G'$ ? Prove the statement or give a counterexample.

8.9. Devise and analyze an algorithm that takes a weighted graph $G$ and finds the smallest change in the cost to a non-minimum spanning tree edge that would cause a change in the minimum spanning tree of $G$ . Your algorithm must be correct and run in polynomial time.

8.10. Consider the problem of finding a minimum-weight connected subset $T$ of edges from a weighted connected graph $G$ . The weight of $T$ is the sum of all the edge weights in $T$ .
(a) Why is this problem not just the minimum spanning tree problem? (Hint: think negative weight edges.)
(b) Give an efficient algorithm to compute the minimum-weight connected subset $T$ .

8.11. Let $T=(V,E')$ be a minimum spanning tree of a given graph $G=(V,E)$ with positive edge weights. Now suppose the weight of a particular edge $e\in E$ is modified from $w(e)$ to a new value ${\hat {w}}(e)$ . We seek to update the minimum spanning tree $T$ to reflect this change without recomputing the entire tree from scratch. For each of the following four cases, give a linear-time algorithm to update the tree:
(a)$e\notin E'$ and ${\hat {w}}(e)>w(e)$ (b) $e\notin E'$ and ${\hat {w}}(e) (c) $e\in E'$ and ${\hat {w}}(e) (d) $e\in E'$ and ${\hat {w}}(e)>w(e)$ 8.12. Let $G=(V,E)$ be an undirected graph. A set $F\subseteq E$ of edges is called a feedback-edge set if every cycle of $G$ has at least one edge in $F$ .
(a)Suppose that $G$ is unweighted. Design an efficient algorithm to find a minimum-size feedback-edge set.
(b)Suppose that $G$ is a weighted undirected graph with positive edge weights. Design an efficient algorithm to find a minimum-weight feedback-edge set.

### Union Find

8.13. Devise an efficient data structure to handle the following operations on a weighted directed graph:
(a)Merge two given components.
(b)Locate which component contains a given vertex $v$ .
(c)Retrieve a minimum edge from a given component.

8.14. Design a data structure that can perform a sequence of, $m$ union and find operations on a universal set of $n$ elements, consisting of a sequence of all unions followed by a sequence of all finds, in time $O(m+n)$ .

8:15

8.16

8.17

8.18

8.19

8.20

8.21

8.22

8.23

8.24

8.25

8.26

8.27

### Network Flow and Matching

8.28

8.29

Back to Chapter List