Vertex Cover Problem

Distribute Education like Computer Geek

Introduction

.

The Vertex Cover Problem is a well-known problem in computer science and graph theory.

This problem is important in the study of NP-completeness because it is one of the NP-complete problems. This means that no fast (polynomial-time) solution is known for it, and it is as hard as any problem in the NP class.

But there is a riddle which you have to solve to understand vertex cover problem.

.

Riddle –

I am a network of roads between towns,
You need to watch each road, ups and downs.
But cameras are costly, and you must be wise,
To cover each road with the smallest prize.

One camera at each town you place,
But not every town—just a few in space.
What is the smallest group, can you guess,
That covers all roads with no road left to stress?

.

Roads and 360 degree cameras

.

Imagine you are designing a city surveillance system where you want to monitor all the streets. Instead of placing a 360-degree camera at every single intersection, you only place 360-degrees cameras at selected intersections (towns) so that every street (road) is watched by at least one camera. Your goal is to use the fewest cameras while still covering all the streets. How do you decide where to place them?

This riddle relates to the Vertex Cover Problem—find the smallest set of intersections (vertices) where 360-degree cameras should be placed to monitor all roads (edges).

.

History

The problem was first formally studied in the context of graph theory in the early 1970s. The problem is linked to various practical applications, such as network security, resource allocation, and scheduling.

In 1972, Stephen Cook introduced the concept of NP-completeness in his seminal paper on the P vs NP problem. The Vertex Cover problem was one of the first problems to be proven NP-complete, making it a fundamental problem in the study of computational complexity.

.

Problem Statement – (2-Approximation Algorithm)

Given an undirected graph G = (V, E), where V is the set of vertices and E is the set of edges, the task is to find a subset of vertices C ⊆ V such that every edge in the graph is incident to at least one vertex in C.

The objective is to minimize the size of this subset.

However, finding the smallest possible vertex cover is an NP-hard problem, making it computationally infeasible for large graphs. To address this, a 2-approximation algorithm is used, which efficiently finds a vertex cover that is at most twice the size of the optimal solution.

.

.

Why there is 2 in 2-Approximation Algorithm?

The “2” in the term 2-approximation algorithm refers to the approximation ratio or the guaranteed bound of the algorithm. This means the solution provided by the algorithm is at most twice (2 times) the size of the optimal solution.

Using the 2-approximation algorithm, find a vertex cover C such that ∣C∣ ≤ 2⋅∣COPT∣

where ∣COPT∣ is the size of the optimal (smallest) vertex cover.

This ensures that the solution is at most twice the size of the optimal solution while maintaining computational efficiency.

.

Algorithm of Vertex Cover
  1. Initialize an empty set C to store the vertex cover.
  2. While there are edges remaining in E
    • Select any edge (u, v) from E.
    • Add both u and v to C.
    • Remove all edges from E that are incident to u or v.
  1. Output the set C as the vertex cover.

.

Example –

We are given a graph, and we need to find the set of vertices (nodes) such that every edge in the graph is covered. This means that for each edge, at least one of its two endpoints (vertices) must be included in the vertex cover.

Vertex Cover Problem Graph

Step 1 – Initialize an empty set C to store the vertex cover.

C = { }

Step 2 – While there are edges in the graph

  • Select any edge (u, v) from E
  • Add both u and v to C.
  • Remove all edges from E that are incident to u or v.

Vertex Cover Problem by Approximation Algorithm

.

You can see in diagram (A), we have taken an edge and the two end vertices are u and v. The red colour vertex is the visited vertex. We have removed all edges related to u and v in (A) case.

In (B), (C), (D) and (E), we introduced new u and v vertex, colour them red and remove all edges related to u and v. In (E), we have covered all the edges.

In this approximation algorithm, we have a Vertex Cover = 10.

.

Although this selection of red vertices successfully covers all the edges, it might not represent the minimal set required to cover every edge. This solution provides a valid but potentially non-optimal vertex cover.

To achieve the minimal vertex cover, we can apply a heuristic algorithm that focuses on the degree of the vertices.

  1. Identify the vertex with the highest degree (the one connected to the most edges).
  2. Add this vertex to the vertex cover because it will cover the most edges at once.
  3. Remove all the edges connected to this vertex (since they are now covered).
  4. Repeat the process with the remaining vertices until all edges are covered.

Green edges are removed Edges

Vertex Cover Problem Graph Solution 2

.

In the heuristic algorithm, we have a Vertex Cover = 6

This approach helps minimize the number of vertices selected for the cover. Though it may not always give the absolute minimal cover (as it’s a heuristic), it often provides a close-to-optimal solution.

This means if the optimal solution has a vertex cover of size 6, the algorithm will find a vertex cover of size at most 2 × 6 = 12.

In the example we discussed, the algorithm gave us a vertex cover of size 10, which satisfies the approximation bound, 10 ≤ 2×6.

.

Source Code for Vertex Cover Problem

Time Complexity

In the worst case, we have to consider each edge of the graph. For each edge, look at vertices, mark as covered, and subtract their connected edges. This has a time complexity of O(V).

Since the edges are up to E in number, the overall time is O(E*V), with E the edges and V the number of vertices.

.

Space Complexity

The graph employs a matrix to keep track of edges, which consumes O(V2) space. The covered array consumes O(V) space and the vertex cover list consumes at most O(V) space.

Therefore, the space complexity is O(V2).

This is because it uses an adjacency matrix in representing the graph. However, reducing the space complexity to O(V+E) is by using an adjacency list instead.

.

Applications

1. Network Design – The vertex cover problem can be applied in designing networks, such as communication networks or computer networks. In this case, the meaning of the vertex cover is selecting a subset of nodes to be covered or protected, and the edges represent the connections that require coverage.

2. Resource allocation – if some resources must be allocated in order to cope with interactions or connections between tasks or systems, then the vertex cover will find the least number of resources to handle all the dependencies.

3. Scheduling Problems – The vertex cover can determine which tasks should be scheduled or monitored so that all inter-task dependencies are considered when planning tasks that depend on one another.

4. Biological Networks – The vertex cover can be used in biological networks, such as protein-protein interaction networks, to find the smallest set of proteins forming part of interactions.

Test Yourself

Q1- Why is the Vertex Cover Problem classified as NP-complete?

The Vertex Cover Problem is NP-complete because verifying a given solution is possible in polynomial time, but no polynomial-time algorithm is known to solve all instances of the problem.

Q2- What is a 2-approximation algorithm, and why is it used for the Vertex Cover Problem?

A 2-approximation algorithm finds a vertex cover within twice the size of the optimal solution. It is used because finding the exact solution is computationally infeasible for large graphs.

Q3- Describe the heuristic method for finding a minimal vertex cover.

The heuristic method selects the vertex with the highest degree, adds it to the vertex cover, and removes all edges incident to it. This process repeats until all edges are covered. The vertex degree indicates the number of edges connected to a vertex. Selecting high-degree vertices first ensures more edges are covered with fewer vertices.

Q4- Provide a real-world application of the Vertex Cover Problem.

A real-world application is in network security, where 360 degrees cameras must be placed at intersections (vertices) to monitor all roads (edges).

Q5- Is it possible for the 2-Approximation Algorithm to include all vertices of the graph in the vertex cover? Under what circumstances?

Yes, in a complete graph Kn​, where n is even. The algorithm includes all vertices since every edge connects every pair of vertices.

Q6- What is the goal of the Vertex Cover Problem?
  1. Find the largest set of vertices
  2. Find the smallest set of vertices
  3. Find the longest path in the graph
  4. Find the shortest path in the graph

Ans – (2)

Explanation – The goal is to find the smallest set of vertices that covers all edges.

Q7- What is the approximation ratio of the 2-approximation algorithm for Vertex Cover?
  1. 1

  2. 1.5

  3. 2

  4. 3

Ans – (3)

Explanation – The solution is guaranteed to be at most twice the size of the optimal solution.

Q8- In the 2-approximation algorithm, how many vertices are added for each selected edge?
  1. 1
  2. 2
  3. 3
  4. 4

Ans – (2)

Explanation – Both endpoints of the selected edge are added to the vertex cover.

Q9- Which of the following graphs has the smallest vertex cover size?
  1. Complete graph
  2. Tree
  3. Bipartite graph
  4. Cycle graph

Ans – (2)

Explanation – In a tree, a minimal vertex cover includes all parent vertices, which is fewer than in other graph types.

Q10- What type of graph structure leads to the largest vertex cover size?
  1. Complete graph
  2. Tree
  3. Sparse graph
  4. Bipartite graph

Ans – (1)

Explanation – In a complete graph, all vertices may be required to cover edges, leading to the largest vertex cover.

BOOKS

Algorithm T H CoremanAlgorithm by Udit AgarwalAlgorithm Ellis HorowitzData Structure & Algorithm Made Easy Narasimha

Â