Homework#14 sample solution: 5-­‐13 (a) Since vertex cover of a graph is NP-­‐hard problem, it only has approximation algorithm. VC = null; // The minimum-­‐size vertex cover while (E !=null && V != null){ pick the vertex u with maximum degree if more than one nodes have maximum degree, choose the one has parent. If all have parent, arbitrarily pick one. VC = VC ∪ {u} delete all edges incident to u and all vertexes adjacent to u } return C (b) and (c) could be solved by the same algorithm as follows: The idea is that you can choose to pick a vertex or not. If you pick it, you can’t pick its direct children but can pick the minimum weight vertex from its grandchildren. We could compute the minimum weight of vertex cover and backtrack to output the vertexes. We add a field to each vertex structure called VC: VC = 0, indicating that this current node is not required to be in the vertex cover set. VC = 1, indicating that this current node is in the vertex cover set For each node, we compute the minimal weight of vertex cover with and without the current node, VC1(the current node is chosen) and VC0 (the current node is not chosen). The recursive function is summarized as follows: If (current node x is leaf node) VC1 = w(x); VC0 = 0; else if (the current node has children(u1, u2, … , uk) k VC1 = (∑ ui. VC0) + w(x) i=1 k VC0 = min(VC1, ( ∑ ui. VC1)) i=1 Eventually, the VC0 at the root node will be the minimal weight of vertex cover. We could backtrack to output the vertexes. 5-­‐14 Deleting all the leaves from any depth-­‐first search tree, of G the remaining vertices still form a vertex cover of G because the parent nodes of the deleted leaves still stay in the graph which is also incident to the same edges with leaves.