Consider a connected undirected graph with edge costs, which need not be distinct. Prove the following statement or provide a counterexample: for every MST of , there exists a way to sort ’s edges in nondecreasing order of cost so that Kruskal’s algorithm outputs the tree .
ANSWER: Given a MST , to obtain this tree with Kruskal’s algorithm, we order the edges first by their weight, and resolve ties by picking an edge first if it is contained in . With this ordering, we will find .
Consider a connected undirected graph with distinct edge costs that are positive integers between and , where is the number of vertices of . How fast can you compute the MST of ?
ANSWER: We may use Radix Sort instead of a comparison sort to sort in linear time. We don’t use Counting Sort 1 because it’s going to take time to go over the buckets. In general, Counting sort takes time, where is the size of the input and is the maximum value of the keys. Once sorted, we may use Kruskal’s algorithm to compute the MST in linear time.
Read about matroids. Prove that the greedy algorithm correctly computes a maximum-weight basis. For the matroid of spanning trees of a graph, this algorithm becomes Kruskal’s algorithm. Can you formulate an analog of Prim’s MST algorithm for matroids?
ANSWER: CLRS section 16.4 has an excellent introduction to Matroids. Also see the Metroid section in the curated list. Quoting CLRS:
A graphic matroid defined in terms of a given undirected graph as follows:
- The set is defined to be , the set of edges of .
- If is a subset of , then iff is acyclic. That is, a set of edges is independent if and only if the subgraph forms a forest.
If we define the weight function such that weight of an edge is given by , then Kruskal’s algorithm becomes a special case of the algorithm in CLRS.
Prim’s algorithm, on the other hand, maintains an induced subgraph . For connected graphs, is a tree, but is not a Matroid since it doesn’t satisfy the hereditary property; removing an edge from a tree may render it disconnected. Therefore, it can’t be formulated in terms of greedy algorithm for Matroids.
Prove that our analysis of union-find with lazy unions and union by rank (but without path compression) is asymptotically optimal (i.e., there are sequences of operations where you do work on most of the operations).
ANSWER: The upper bound is proven is lecture video 7.3. For the lower bound, consider doing a find operation on the leaf node in a path of length (the longest possible). Since we must traverse all nodes on the way to the root, the time taken is equal to the length of the path. Thus, time complexity of find is .
Prove that in our union-find data structure with lazy unions, union by rank, and path compression, some operations might require time.
ANSWER: See Tarjan’s paper in the curated list.