Find minimum vertex Cover for bipartite graph given the maximum matching - algorithm

I seem to have found an algorithm but am having trouble understanding it, I was wondering if any of you knew the generic outline of the algorithm.
Here is the link to the algorithm I found on page 2
http://www.cse.iitb.ac.in/~sundar/cs435/lecture23.pdf

Algorithm is simple as that:
Find unmatched vertex, mark it as not included in minimum vertex cover.
Mark all matched neighbours of this vertex as included in minimum vertex cover.
Treat all mates of vertexes from previous step as unmatched vertexes and repeat step 1.
If recursion ended, repeat from step 1 (that is case of several connected components of graph).
If there is no unmatched vertexes, take all remaining pairs and mark them any way you like (remember that one vertex in pair has to
be included in minimum vertex cover, and other one has to be not
included).

first you should know bipartite graph, two sets of vertexes, and edges, ok, you know that now.
then you need to choose some vertexes from the two sets, to cover all the edges. As long as one vertex is chosen, all the edges link to it is covered. Now your task is to choose the minimum number of vertexes, to cover all the edges.
the principle means, the minimum number you need equals to the number of max matching pairs.

Related

Minimum vertex cover

I am trying to get a vertex cover for an "almost" tree with 50,000 vertices. The graph is generated as a tree with random edges added in making it "almost" a tree.
I used the approximation method where you marry two vertices, add them to the cover and remove them from the graph, then move on to another set of vertices. After that I tried to reduce the number of vertices by removing the vertices that have all of their neighbors inside the vertex cover.
My question is how would I make the vertex cover even smaller? I'm trying to go as low as I can.
Here's an idea, but I have no idea if it is an improvement in practice:
From https://en.wikipedia.org/wiki/Biconnected_component "Any connected graph decomposes into a tree of biconnected components called the block-cut tree of the graph." Furthermore, you can compute such a decomposition in linear time.
I suggest that when you marry and remove two vertices you do this only for two vertices within the same biconnected component. When you have run out of vertices to merge you will have a set of trees not connected with each other. The vertex cover problem on trees is tractable via dynamic programming: for each node compute the cost of the best answer if that node is added to the cover and if that node is not added to the cover. You can compute the answers for a node given the best answers for its children.
Another way - for all I know better - would be to compute the minimum spanning tree of the graph and to use dynamic programming to compute the best vertex cover for that tree, neglecting the links outside the tree, remove the covered links from the graph, and then continue by marrying vertices as before.
I think I prefer the minimum spanning tree one. In producing the minimum spanning tree you are deleting a small number of links. A tree with N nodes had N-1 links, so even if you don't get back the original tree you get back one with as many links as it. A vertex cover for the complete graph is also a vertex cover for the minimum spanning tree so if the correct answer for the full graph has V vertices there is an answer for the minimum spanning tree with at most V vertices. If there were k random edges added to the tree there are k edges (not necessarily the same) that need to be added to turn the minimum spanning tree into the full graph. You can certainly make sure these new edges are covered with at most k vertices. So if the optimum answer has V vertices you will obtain an answer with at most V+k vertices.
Here's an attempt at an exact answer which is tractable when only a small number of links are added, or when they don't change the inter-node distances very much.
Find a minimum spanning tree, and divide edges into "tree edges" and "added edges", where the tree edges form a minimum spanning tree, and the added edges were not chosen for this. They may not be the edges actually added during construction but that doesn't matter. All trees on N nodes have N-1 edges so we have the same number of added edges as were used during creation, even if not the same edges.
Now pretend you can peek at the answer in the back of the book just enough to see, for one vertex from each added edge, whether that vertex was part of the best vertex cover. If it was, you can remove that vertex and its links from the problem. If not, the other vertex must be so you can remove it and its links from the problem.
You now have to find a minimum vertex cover for a tree or a number of disconnected trees, and we know how to do this - see my other answer for a bit more handwaving.
If you can't peek at the back of the book for an answer, and there are k added edges, try all 2^k possible answers that might have been in the back of the book and find the best. If you are lucky then added link A is in a different subtree from added link B. In that case you can confine the two calculations needed for the two possibilities for added link A (or B) to the dynamic programming calculations for the relevant subtree so you have only doubled the work instead of quadrupled it. In general, if your k added edges are in k different subtrees that don't interfere with each other, the cost is multiplied by 2 instead of 2^k.
Minimum vertex cover is an NP complete algorithm, which means that you can not solve it in a reasonable time even for something like 100 vertices (not to mention 50k).
For a tree there is a polynomial time greedy algorithm which is based on DFS, but the fact that you have "random edges added" screws everything up and makes this algorithm useless.
Wikipedia has an article about approximation algorithm, claims that it reaches factor 2 and claims that no better algorithm is know, which makes it quit unlikely that you will find one.

How do I explore a directed graph (DAG) by visting minimum number of starting vertices?

Given a DAG (possibly not strongly connected e.i consisting of several connected components), the goal is to find the minimum number of starting vertices required to visit to fully explore the graph.
One method I thought of was to generate all permutations of the given vertices and run a topological sort in that order. The one with the minimum backtracks would be the answer.
Is there an efficient algorithm to perform the above task?
This a famous problem called minimum path cover, it's a pity that wiki says nothing about it, you can search it in google.
As methioned, the minimum path cover problem is NP-hard in normal graph. But in DAG, it can be solved with Matching.
Method:
Dividing each vertex u into two different vertex u1 and u2. For every edge (u->v) in orginal graph, adding edge (u1->v2) in new graph. Then do any matching algorithm you like. The result is n - maximum matching, n is total number of vertex in orginal graph.

Finding a size of maximum subset of graph in which each vertex a degree atleast p

Given a undirected graph. How to find the size of maximum subset of vertices of the graph in which each vertex has at degree atleast p, where the degree in subset is find among the vertices in subset only.
Vertices of degree less than p can never be part of the solution. Remove them entirely, including their edges. Look at the new graph and repeat, etc.
When this process stops, all vertices have degree at least p.
Then, look at the connected components of that graph and pick the largest one! (As Evgeny Kluev correctly points out, this is unnecessary of course. In my head, the remaining subgraph should have been connected, but of course the original problem makes no such demands.)

Completely disconnecting a bipartite graph

I have a disconnected bipartite undirected graph. I want to completely disconnect the graph. Only operation that I can perform is to remove a node. Removing a node will automatically delete its edges. Task is to minimize the number of nodes to be removed. Each node in the graph has atmost 4 edges.
By completely disconnecting a graph, I mean that no two nodes should be connected through a link. Basically an empty edge set.
I think, you cannot prove your algorithm is optimal because, in fact, it is not optimal.
To completely disconnect your graph minimizing the number of nodes to be removed, you have to remove all the nodes belonging to the minimal vertex cover of your graph. Searching the minimal vertex cover is usually NP-complete, but for bipartite graphs there is a polynomial-time solution.
Find maximum matching in the graph (probably with Hopcroft–Karp algorithm). Then use König's theorem to get the minimal vertex cover:
Consider a bipartite graph where the vertices are partitioned into left (L) and right (R) sets. Suppose there is a maximum matching which partitions the edges into those used in the matching (E_m) and those not (E_0). Let T consist of all unmatched vertices from L, as well as all vertices reachable from those by going left-to-right along edges from E_0 and right-to-left along edges from E_m. This essentially means that for each unmatched vertex in L, we add into T all vertices that occur in a path alternating between edges from E_0 and E_m.
Then (L \ T) OR (R AND T) is a minimum vertex cover.
Here's a counter-example to your suggested algorithm.
The best solution is to remove both nodes A and B, even though they are different colors.
Since all the edges are from one set to another, find these two sets using say BFS and coloring using 2 colours. Then remove the nodes in smaller set.
Since there are no edges among themselves the rest of the nodes are disconnected as well.
[As a pre-processing step you can leave out nodes with 0 edges first.]
I have thought of an algorithm for it but am not able to prove if its optimal.
My algorithm: On each disconnected subgraph, I run a BFS and color it accordingly. Then I identify the number of nodes colored with each color and take the minimum of the two and store. I repeat the procedure for each subgraph and add up to get the required minimum. Help me prove the algorithm if it's correct.
EDIT: The above algorithm is not optimal. The accepted answer has been verified to be correct.

Perfect matching in a tree

I came across a definition of Perfect matching: a set of edges that touches each node exactly once.
However, i didnt really understand the definition. Can somebody give me an example of any such edge. Or may be point me towards some reference that does.
I tried to google but it didnt give me any example.
A perfect matching set is any set of edges in a graph where every vertex in the graph is touched by exactly one edge in the matching set. If you consider a graph with 4 vertices connected so that the graph resembles a square, there are two perfect matching sets, which are the pairs of parallel edges. Since all the vertices are touched exactly once by either pair. If you think about a graph with 3 vertices connected like a triangle, there is no perfect matching set, because if you take any pair of edges, one vertex is touched twice, but a single edge will always miss a vertex.
http://en.wikipedia.org/wiki/Perfect_matching
Your question mentions a tree, but a tree is just a special type of graph, so it still works the same.
In fact, any graph with odd number of vertices cannot have a perfect matching edge set.
N edges => 2 * N vertices. Since no vertex once touched should not be touched again.

Resources