  A Vertex Cover (VC) of a connected undirected (un)weighted graph G is a subset of vertices V of G such that for every edge in G, at least one of its endpoints is in V. A Minimum Vertex Cover (MVC) of G is a VC that has the smallest cardinality (if unweighted) or total weight (if weighted) among all possible VCs. A graph can have multiple VC but the value of MVC is unique.

There is another problem called Maximum Independent Set (MIS) that attempts to find the largest subset of vertices in a (un)weighted graph G without any adjacent vertices in the subset. Interestingly, the complement of an MVC of a graph is an MIS.

At the end of every visualization, when an algorithm highlights an MVC solution to a graph, it will also highlight its MIS (which is its complement) with light blue color.

Remarks: By default, we show e-Lecture Mode for first time (or non logged-in) visitor.

X Esc

There are two available modes: Unweighted (default) and Weighted. You can switch between the two modes by clicking the respective tab.

There are algorithms that work in both modes and there are algorithms that only work in a certain mode.

Pro-tip: Since you are not logged-in, you may be a first time visitor who are not aware of the following keyboard shortcuts to navigate this e-Lecture mode: [PageDown] to advance to the next slide, [PageUp] to go back to the previous slide, [Esc] to toggle between this e-Lecture mode and exploration mode.

X Esc

View the visualisation of the selected MVC algorithms here.

Originally, all vertices and edges in the input graph are colored with the standard black outline. As the visualization goes on, the color light blue will be used to denote covered edges and the color orange on edge will be used to show traversed edges.

At the end of the selected MVC algorithm, if it finds a minimum VC, it will highlight the MVC vertices with orange color and the non MVC vertices (a.k.a. the MIS vertices) with lightblue; color. Otherwise, if the found vertex cover is not proven to be the minimal one (e.g. the algorithm used is an approximation algorithm), it will highlight the vertices that belong to the found vertex cover with orange color without highlighting the MIS vertices.

Another pro-tip: We designed this visualization and this e-Lecture mode to look good on 1366x768 resolution or larger (typical modern laptop resolution in 2017). We recommend using Google Chrome to access VisuAlgo. Go to full screen mode (F11) to enjoy this setup. However, you can use zoom-in (Ctrl +) or zoom-out (Ctrl -) to calibrate this.

X Esc

There are two different sources for specifying an input graph:

1. Draw Graph: You can draw any connected (un)directed weighted graph as the input graph.
2. Example Graphs: You can select from the list of example connected undirected weighted graphs to get you started.
X Esc

Bruteforce: It tries all possible 2^V subset of vertices. In every iteration, it checks whether the currently selected subset of vertices is a valid vertex cover by iterating over all E edges and check whether there is any edge that is not covered by the vertices in the currently selected subset. This bruteforce algorithm keeps the smallest size of the valid vertex cover as the answer.

This bruteforce algorithm is available in both weighted and unweighted version.

Its time complexity is O(2^V × E), i.e. very slow.

X Esc

DP on Tree: If the graph is a tree, the MVC problem can be formulated as a Dynamic Programming problem where the states are (position, take_current_vertex).

Then, it can be seen that:
DP(u, take) = cost[u] + sum(min(DP(v, take), DP(v, not_take))) ∀child v of u, and
DP(u, not take) = sum(DP(v, take)) ∀child v of u

This DP algorithm is available in both weighted and unweighted version.

Its time complexity is O(V), i.e. very fast, if the input graph is a tree.

X Esc

Greedy MVC on Tree: Again, if the graph is an unweighted tree, it can be solved greedily by observing that if there is any MVC solution that takes a leaf vertex, we can obtain a "not worse" solution by taking the parent of that leaf vertex instead. After removing all covered vertices, we can apply the same observation and repeat it until every vertex is covered.

This greedy MVC algorithm is only available in unweighted mode.

Its time complexity is O(V), i.e. very fast, if the input graph is an unweighted tree.

X Esc

Kőnig's Theorem: From Kőnig's Theorem, the size of MVC in an unweighted bipartite graph is equal to the cardinality of the maximum matching of the bipartite graph. In the case of weighted bipartite graph, we can see that this theorem also holds true, with a tweak in how we construct the graph. In this visualization, we use a reduction to max flow problem to get the value of the MVC.

This algorithm is available in both weighted and unweighted version.

Its time complexity is O(V × E) (for unweighted version; can be smaller with pre-processing) or O(E^2 × V)/O(V^2 × E) (for weighted version, depending on the max flow algorithm used).

X Esc

There are several known approximation algorithms for MVC:

1. For unweighted version, we have either the deterministic 2-approximation or probabilistic 2-approximation (in expectation),
2. For weighted version whe have the Bar-Yehuda and Even's 2-approximation algorithm.

Note that these algorithms only yield an "approximated" MVC, meaning that they are not a true minimum vertex cover, but a good enough one.

X Esc

X Esc

e-Lecture: The content of this slide is hidden and only available for legitimate CS lecturer worldwide. Drop an email to visualgo.info at gmail dot com if you want to activate this CS lecturer-only feature and you are really a CS lecturer (show your University staff profile).

X Esc

-／+：减缓／增加速度

X Esc

Note that if you notice any bug in this visualization or if you want to request for a new visualization feature, do not hesitate to drop an email to the project leader: Dr Steven Halim via his email address: stevenhalim at gmail dot com.

X Esc

Bruteforce

MVC on Tree

MVC on Bipartite Graph General Graph

Linear Chain

Unweighted 2-approx Killer

Weighted 2-approx Killer

Tree

K5

Bipartite Graph

CS4234 Sample

DP on Tree

Greedy MVC on Tree

Kőnig's Theorem

Deterministic 2-opt

Probabilistic 2-opt

#### 关于

VisuAlgo在2011年由Steven Halim博士概念化，作为一个工具，帮助他的学生更好地理解数据结构和算法，让他们自己和自己的步伐学习基础。
VisuAlgo包含许多高级算法，这些算法在Steven Halim博士的书（“竞争规划”，与他的兄弟Felix Halim博士合作）和其他书中讨论。今天，一些高级算法的可视化/动画只能在VisuAlgo中找到。

VisuAlgo不是从一开始就设计为在小触摸屏（例如智能手机）上工作良好，因为需要满足许多复杂的算法可视化，需要大量的像素和点击并拖动手势进行交互。一个令人尊敬的用户体验的最低屏幕分辨率为1024x768，并且只有着陆页相对适合移动设备。
VisuAlgo是一个正在进行的项目，更复杂的可视化仍在开发中。

zh, id, kr, vn, th.

#### 团队

Dr Steven Halim, Senior Lecturer, School of Computing (SoC), National University of Singapore (NUS)
Dr Felix Halim, Software Engineer, Google (Mountain View)

Koh Zi Chun, Victor Loh Bo Huai

Phan Thi Quynh Trang, Peter Phandi, Albert Millardo Tjindradinata, Nguyen Hoang Duy

Rose Marie Tan Zhao Yun, Ivan Reinaldo

Jonathan Irvin Gunawan, Nathan Azaria, Ian Leow Tze Wei, Nguyen Viet Dung, Nguyen Khac Tung, Steven Kester Yuwono, Cao Shengze, Mohan Jishnu

Erin Teo Yi Ling, Wang Zi

Truong Ngoc Khanh, John Kevin Tjahjadi, Gabriella Michelle, Muhammad Rais Fathin Mudzakir

List of translators who have contributed ≥100 translations can be found at statistics page.