bipartite-vertex-cover
Version:
Minimal vertex cover for bipartite graphs
39 lines (29 loc) • 1.32 kB
Markdown
bipartite-vertex-cover
======================
Computes a [minimum vertex cover](http://en.wikipedia.org/wiki/Vertex_cover) of a bipartite graph. Internally, this implementation uses the Hopcroft-Karp algorithm and [Konig's theorem](http://en.wikipedia.org/wiki/K%C3%B6nig's_theorem_\(graph_theory\)) to compute the minimal vertex cover of a bipartite graph in O(sqrt(V) * E) time. This code works in both node.js and in a modern browser via [browserify](http://browserify.org/).
```javascript
var findCover = require("bipartite-vertex-cover")
var cover = findCover(4, 4, [
[],
[],
[],
[],
[],
[],
[]
])
// Cover = [ [3, 1], [1] ]
```
```
npm install bipartite-vertex-cover
```
Finds a minimal vertex cover for a bipartite graph.
* `n` is the number of vertices in the left component
* `m` is the number of vertices in the right component
* `edges` is a list of edges from the left component connecting to the right component represented by pairs of integers between 0 and n-1,m-1 respectively
**Returns** A pair of lists representing the vertices in the left component and the right component respectively which are in the cover.
(c) 2014 Mikola Lysenko. MIT License