4

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.

Mukul Gupta
  • 2,310
  • 3
  • 24
  • 39

4 Answers4

7

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.

Community
  • 1
  • 1
Evgeny Kluev
  • 24,287
  • 7
  • 55
  • 98
  • I have implemented the Hopcroft-Karp algorithm as illustrated in wikipedia. Can someone suggest an optimization over it? I need a faster implementation. I have around 1 million nodes but edges are less with 1 node having atmost 4 edges. – Mukul Gupta Aug 08 '12 at 05:57
  • @user1112010: Some pre-processing may help here. Since your graph is already disconnected (contains several components), you might start with extracting these components, and then apply the Hopcroft-Karp algorithm to each component separately. Also it is worth to start a new question about faster implementation for the Hopcroft-Karp algorithm. Or you might ask if there exist any better (than Hopcroft-Karp) algorithm for your particular graph (probably on cs.stackexchange.com or http://cstheory.stackexchange.com). – Evgeny Kluev Aug 08 '12 at 10:27
  • http://apps.topcoder.com/forums/?module=Thread&threadID=685411&start=0&mc=9 I got the answer here :) – Mukul Gupta Aug 08 '12 at 10:32
3

Here's a counter-example to your suggested algorithm.

enter image description here

The best solution is to remove both nodes A and B, even though they are different colors.

Xantix
  • 3,321
  • 1
  • 14
  • 28
  • This is exactly my comment, but in picture form - this should really be a comment to that answer, not a standalone answer... – BlueRaja - Danny Pflughoeft Aug 07 '12 at 17:08
  • 1
    @BlueRaja-DannyPflughoeft I saw your comment after designing this picture. It is true this isn't the answer. But there isn't a very good way to insert a pic into a comment, although I could comment with a link to this image, and hope that some 3rd party pic sharing site keeps it available. (if you know a way to insert a pic into a comment please tell me.) (I would upvote your comment if it was as easy to understand as this pic.) – Xantix Aug 07 '12 at 21:50
0

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.

Mukul Gupta
  • 2,310
  • 3
  • 24
  • 39
  • 2
    Won't work for the following simple case: Add a bunch of nodes (with no edges) to both the left and the right. Then add one node to the left and connect it to all nodes on the right; and add one node on the right and connect it to all nodes on the left. Then minimal vertex cover contains those last two nodes, but your algorithm will find all the nodes on one side. – BlueRaja - Danny Pflughoeft Aug 06 '12 at 20:26
0

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.]

Fakrudeen
  • 5,778
  • 7
  • 44
  • 70