Is there any algorithm to find Isomorphism function between two graphs?

This a very interesting question which I am afraid has (as of the moment) a somewhat disappointing answer.

The problem of graph isomorphism has been an object of study of Computational Complexity since the beginnings of the field. It is clearly a problem belonging to NP, that is, the class of problems for which the answers can be easily verified given a 'witness'- an additional piece of information which validates in some sense the answer.

For example, given two isomorphic graphs a witness of its isomorphism could be the permutation which transforms one graph into the other.

Now for the interesting part. NP is further divided into P (polynomial time solveable) problems, NP-complete problems and NP-intermediate problems. An NP complete problem is one whose solution can be used to encode any other NP problem, meaning that if you could efficiently solve one NP-complete problem, you could efficiently solve all of them, and thus $P=NP$.

However, most researchers believe that $P\ne NP$. One of the consequences of this
is the existence of NP-intermediate problems (Ladner's theorem) - problems which
are in NP but are not in P nor NP-complete. One remarkable aspect of the proof of
Ladner's theorem is that the hypothetical language constructed is very unnatural.
It is an open problem to find an actual NP-intermediate language.

Some contenders have been disqualified as potential candidates for NP-intermediateness, but graph isomorphism is one of the remaining. We do not actually know whether GI is in P, NP-complete or NP-intermediate.

The evidence however suggests that it is either NP-intermediate or in P. There is a very recent advance, due to Babai, which shows that GI is solvable in quasi-polynomial time, which is something we would not expect from a NP-complete problem.

Hope I have not left any major detail out. Feel free to ask questions about GI or its cousin, graph non-isomorphism.


As other commenters have pointed out, there is no simple algorithm for all graphs that runs very fast. I know that 'very fast' is vague, but I'm not able to discuss the complexity of the problem particularly well.

However...

For many classes of graph - such as those of bounded degree, treewidth, etc - there are various algorithms to determine an isomorphism function that will map one to the other.

One approach is based on partition refinement. This is quite well described here but I'll give a short description as I understand it. Note that this is broadly the technique used by nAUTy and similar programs (bliss, traces, saucy) to compute graph isomorphisms and automorphisms.

What is required for isomorphism between two graphs - G, H - is a canonical labelling (cl) for each such that cl(G) = cl(H). If you simply wanted to test for isomorphism, then you could calculate a 'certificate' for both. For a pair of trees, this is as simple as a string formed by recursively building up from the leaves (labelled '01'), sorting at each stage, until you get to the root (see the description starting "For trees..." in the wiki page for canonical labelling).

To get the actual mapping, we need to create an actual canonical labelling - in other words, choose a particular permutation for each graph that 'relabels' it into the canonical form. This is where partition refinement comes in. Starting with a root partition - such as the partition of the vertices by degree - we successively 'refine' the partition until we get permutations. Permutations are, in this view, just 'discrete' partitions with one vertex in each block.

Here, a partition A is 'finer' than another partition B if we have split up one or more of the blocks of A to get B. Depending on how we choose which block to split next, and how the blocks are ordered in the refined child partition, we get a particular labelling. The refinement procedure forms a tree of partitions, with permutations as the leaves - and we choose (say) the first one we reach.

There is obviously a lot more to this subject, but a good introduction to this I found in this book called "Computational Algorithms : Generation Enumeration and Search" by Kreher and Stinson.


If you had a polynomial-time algorithm (with a known polynomial complexity bound, say $C n^p$) to find an isomorphism for a pair of graphs that are in fact isomorphic, you could use that to determine in polynomial time whether two graphs are isomorphic. Namely, you run the algorithm with a time limit of $C n^p$, and check whether it produces an isomorphism. Note that it's easy to check in polynomial time whether something is an isomorphism of the graphs.

If your two graphs happen to be isomorphic, then by assumption the algorithm will produce an isomorphism within that time limit, and your isomorphism checker will verify that it is an isomorphism. If they aren't, then what can happen? Either the algorithm will run over the time limit, or it will stop within the time limit with some result (perhaps an error message, or maybe something that isn't an isomorphism), and your isomorphism checker will show that this isn't an isomorphism.

As others have mentioned, we don't curently have a polynomial-time algorithm to decide graph isomorphism, and there is some reason to believe that no such algorithm exists.

However, that is all worst-case complexity. In more "typical" cases, graph isomorphism is relatively easy. See e.g. McKay and Piperno, "Practical Graph Isomorphism II".