For a nontrivial connected graph, return the internal vertices of a rooted tree in a depth-first search tree. Undirected depth-first search has only ancestor-descendant edges, so every edge meets an internal vertex; the internal vertices are connected along parent paths. For a maximum-size proper matching in a rooted tree of that tree, existence of which is assumed, . Every vertex cover has size at least , proving the factor two. The implementation needs only depth-first search, hence linear time complexity; it does not compute the analysis matching in a graph.
Past exam of the computer science course of the University of Oxford 2018 Algorithms 2 e Solution 2026-10-31
We construct an injection from the unmatched vertices in a matching to the leaves of a rooted tree. Start a downward graph path at each unmatched vertex . If the current vertex is a leaf of a rooted tree, stop. Otherwise choose any child . The current vertex is either the unmatched starting point or a vertex already matched to its own parent.
In either case, cannot be unmatched: the proper matching in a rooted tree condition would require its parent to be matched to one of 's siblings in a rooted tree, whereas that parent is either unmatched or already matched upward. Nor can be matched to its parent. Its matching partner must therefore be one of its own children, say . Extend the graph path by the two edges to and then to , and continue from .
Every extension descends two levels, so finiteness guarantees termination at a leaf of a rooted tree. Every visited vertex except the starting point is matched. The constructed graph paths for different unmatched starting points are disjoint: if two downward graph paths in a tree meet, one starting point must lie on the other path, which would put a second unmatched vertex after the first. That is impossible. Hence their terminal leaves of a rooted tree are distinct, provingOnly the properness condition for unmatched non-root vertices was used. If the root is unmatched and the convention exempts it because it has no parent, the same construction starts there and still works. Thus the root convention does not affect the claimed inequality. This proves the unmatched-vertex bound for a proper tree matching without requiring to have maximum size.
Past exam of the computer science course of the University of Oxford 2018 Algorithms 2 f Solution 2026-10-31
For a connected graph with at least one edge, run depth-first search and output the set of internal vertices of a rooted tree in its discovery tree . Part (d) proves that is a vertex cover. It is also connected: every ancestor of an internal vertex is internal, so the graph path in from that vertex to the root stays inside . The root is internal when .
For the approximation guarantee, choose a maximum-size proper matching in a rooted tree of , whose existence is supplied. It is used only in the analysis; the algorithm need not construct it. Since every matched edge uses two distinct vertices,By part (e), . ThereforeThe final inequality holds because every vertex cover of , connected or otherwise, must use at least one distinct endpoint for each of the disjoint edges in . Thus this is a 2-approximation algorithm in time complexity.
For completeness, a disconnected input needs a feasibility check: if two different connected components of a graph contain edges, no connected vertex cover can meet both. If exactly one component contains edges, run the construction on that component and ignore isolated vertices. If there are no edges, the empty vertex cover is optimal when an empty solution is permitted; if a nonempty connected solution is required, any single vertex is optimal for a nonempty input. These conventions cover the boundary cases omitted from the main approximation argument.
For a proper matching in a rooted tree, the number of unmatched vertices in a matching does not exceed the number of leaves of a rooted tree. From each unmatched vertex, build a downward path: at an internal current node that is unmatched or matched upward, every child must be matched downward to one of its own children, or properness would fail. Follow a child and its matching partner, then repeat. The path terminates at a leaf and contains no other unmatched vertex. Two such downward paths cannot meet, since then one unmatched starting point would lie on the other's path. Their distinct endpoints give the required injection. No maximum-size assumption is needed.