isomorphism

Finds a node mapping that makes two graphs identical.

Category: Mathematics > Graph and Network Algorithms

Syntax

p = isomorphism(G1, G2)

Returns a node permutation, or an empty array if the graphs are not isomorphic.

Description

When the graphs are isomorphic, relabeling node i of G1 as p(i) reproduces G2. More than one mapping may exist (a symmetric graph has many) and the function returns one of them.

Use isisomorphic when only a yes or no answer is needed.

Input arguments

G1, G2
Two graphs of the same kind.

Output arguments

p
Column vector: p(i) is the node of G2 that corresponds to node i of G1.

Example

Matching a path

A = graph([1 2], [2 3]);
B = graph([1 3], [3 2]);
p = isomorphism(A, B)'
Output
p = 1×3

     1     3     2

See also

isisomorphic reordernodes graph degree