Algorithm Pseudo Code

suggest change

Algorithm PMinVertexCover (graph G)

Input connected graph G

Output set C

Set C <- new Set<Vertex>() 

Set X <- new Set<Vertex>() 

X <- G.getAllVerticesArrangedDescendinglyByDegree()

for v in X do
    List<Vertex> adjacentVertices1 <- G.getAdjacent(v)

    if !C contains any of adjacentVertices1 then
        
        C.add(v)

for vertex in C do

    List<vertex> adjacentVertices2 <- G.adjacentVertices(vertex)

    if C contains any of adjacentVertices2 then
        
        C.remove(vertex)

        
return C

C is not always a vertex cover, and it is not always a minimum one. See the triangle counterexample on the previous page.

Bucket sort can order the vertices by degree, because every degree is at most n - 1. That sort takes O(n) time.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents