Greedy degree procedure for vertex cover
suggest changeIntroduction
The procedure below runs in O(n^2) on a connected undirected graph, but it is not an algorithm for the minimum vertex cover. That problem is NP-hard. The second loop deletes a selected vertex whenever one of its neighbors was also selected, which can leave an edge uncovered. On a triangle it keeps a single vertex, so the opposite edge is not covered.
Parameters
Variable | Meaning |
—— | —— |
G | Input connected un-directed graph |
X | Set of vertices |
C | Final set of vertices|
Remarks
Sort the vertices in descending order of degree.
Then iterate through them and add a vertex to the result when none of its neighbors is already in the result.
Finally, iterate through the result and remove every vertex that has a neighbor in the result. That last pass is what can destroy the cover.