-1

I am having a bipartite graph with N nodes in one side and almost 100 in other side. Now i need to count the matchings such that each node in first part is having a link to some node in other part such that no two nodes in first part matches to same node in second part.(Just like one job can be assigned to one applicant only)

Now I know that finding this count is not easy and is #P-hard problem ( from link : https://cs.stackexchange.com/questions/19924/counting-and-finding-all-perfect-maximum-matchings-in-general-graphs )

But what can be the brute solution to do so ?Can someone please explain with some code or pseudocode.

Assume input is like we have X pairs showing u is connected to v

If N=2 and X=4 and pairs be (1,1),(1,2),(2,3),(2,4).

Community
  • 1
  • 1

1 Answers1

1

There may be a dynamic programming solution for small N, where 2^N is a practical number.

Represent the graph by an N x 100 table, with entries marked true when there is a link from one side to the other side. For i = 1..100 we will work out Count(i, x) where x is in the range 0..2^N-1 and represents a set of the nodes on the N side. Count(i, x) will be a count of the number of matchings between the nodes in set x in the N side and the first i nodes in the 100 side.

We can work out Count(i, x) from Count(i-1, *) by considering the cases when there is a match between i and one of the nodes in x and the case where there is not. The case where there is not scores Count(i - 1, x) - the number of way to create a matching not using i. For each set bit in x if there is a link from i to the node represented by that bit, let y by be the bit pattern for x with that bit not set and add Count(i - 1, y) to the count so far. Count(i, x) is the sum of all of these counts.

The final answer is Count(100, 2^N-1) - the number of matchings between the first 100 nodes on one side and all of the N nodes on the other side.

mcdowella
  • 19,301
  • 2
  • 19
  • 25
  • Could you please explain more with some example or pseudocode or some code snippet.Anything that you are suitable with – user3907074 Aug 04 '14 at 17:32