Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one implement graph algorithms that require efficient contraction and expansion of connected components?

There are some algorithms, like Edmond's Algorithm, or Boruvka's Algorithm which require the programmer to create a graph which is obtained by contraction of some nodes into a single node, and later expanding it back.

A formal description of contraction is as follows:

Let G be a graph with vertices V and edges E. Let C be a connected component of G. A contraction of G with respect to C is defined as the graph on V - nodes(C) + C*, where C* is a "supernode" representing the contracted component. The edges which do not involve vertices in C are as is. The edges which had an endpoint in C are now connected to C*.

For example, an intermediate step in Edmond's Algorithm might require contracting a cycle, operating on the contracted graph, and then expanding it back again

It is not clear to me how to implement such algorithmic primitives using representations like adjacency lists.

What would be an elegant and efficient way to represent graphs so that they can be contracted, while remembering the relevant data for expanding them?

like image 296
Agnishom Chattopadhyay Avatar asked Apr 01 '18 11:04

Agnishom Chattopadhyay


People also ask

What are the ways to implement graph data structure?

A graph can be represented using 3 data structures- adjacency matrix, adjacency list and adjacency set.

Which algorithm can be used to find all the connected components of a graph?

We can use a traversal algorithm, either depth-first or breadth-first, to find the connected components of an undirected graph. If we do a traversal starting from a vertex v, then we will visit all the vertices that can be reached from v.

How do you ensure a graph is connected?

A simple solution is to perform Depth–first search (DFS) or Breadth–first search (BFS) starting from every vertex in the graph. If each DFS/BFS call visits every other vertex in the graph, then the graph is strongly connected. The algorithm can be implemented as follows in C++, Java, and Python: C++

What are two methods to implement graphs in memory?

There are two ways to store Graphs into the computer's memory: Sequential representation (or, Adjacency matrix representation) Linked list representation (or, Adjacency list representation)


1 Answers

I would use disjoint-set data structure also called a union–find data structure . Imagine each vertex as a set initially. Now the working goes like this:

For contraction: Take the union of all the vertices participating in all the contraction. All the vertices in a set are represented by single vertex called parent of all vertices, which you can call your supernode. The link has all the details of how to do that.

For expansion just do the reverse, in the worst case you would have to make each vertex represent a single set. So basically this approach works for non-overlapping set operations.

like image 51
Sumeet Avatar answered Oct 05 '22 23:10

Sumeet