0

Question: Let T be an n-node tree rooted at some node r. We want to place as few guards as possible on nodes of T, such that every edge of T is guarded: an edge between a parent node v and its child w is guarded if one places a guard on at least one of these two nodes v, w. Give an O(n) time algorithm for finding an optimal solution to the problem.

My approach was to do post order traversal from the root and place a guard on a node that is part of an unguarded edge except if that node is a leaf...but this algorithm wouldn't work if all the nodes were arranged in a linear chain because my algorithm would place guards on every node except for the ends of the chain.

I've looked online and checked out the DP solutions, which make sense to me but I was wondering if there's a greedy algorithm to find a vertex cover for a tree

Howard Wang
  • 422
  • 6
  • 14
  • Can you explain that why your solution doesn't work? – ZhaoGang Dec 11 '18 at 10:17
  • Yeah so if the vertices were the following v1->v2->v3->v4->v5 (like a path instead of a tree structure) my algorithm would choose v4, v3, and v2 instead of just v4 and v2 – Howard Wang Dec 11 '18 at 22:14
  • see the `Exact Evaluation` section of the wikipedia page of Vertex cover:`For tree graphs, an algorithm finds a minimal vertex cover in polynomial time by finding the first leaf in the tree and adding its parent to the minimal vertex cover, then deleting the leaf and parent and all associated edges and continuing repeatedly until no nodes remain in the tree. ` IMHO,this should be a linear solution – ZhaoGang Dec 12 '18 at 12:21

0 Answers0