Message Boards Message Boards


A sub graph match comparison

Posted 1 year ago
3 Replies
1 Total Likes


I'm trying to do a comparison between a main graph and a sub graph. Simply put, is there a native function to do this job or should I do search and compare in the the following way:

Triangular grid as a main grap:

a = ResourceFunction["WolframModel"][{{x, y}} -> {{x, y},{y, z},{z, x}}, {{1, 2}}, 2, "FinalState"]


b = ResourceFunction["WolframModel"][{{x, y}} -> {{x, y},{y, z},{z, x}}, {{1, 2}}, 1, "FinalState"]


c = ResourceFunction["WolframModel"][{{x, y}} -> {{x, y},{y, z},{z, u},{u, x}}, {{1, 2}}, 1, "FinalState"]

Looging for triangle:

s = Subgraph[b,b]
Subgraph[a,b] == s -> TRUE

Looginf for square:

Subgraph[a,c] == s -> FALSE

Before I'm going to write a function for the comparison, I'd like to know what is the best way doing this?

3 Replies

Hi Marko,

Take a look at IsomorphicGraphQ.

Hi Rohit,

I took a look at that, but I'm not sure how to use it:


That won't give the desired result. It looks like the function requires the same amount of points in the graph, but in my case, I want to know if subgraph exists in the main graph. The main graph may be a huge grid of points and the subgraph just a small part. I need to know if a small graph exists inside the big graph as directed (and undirected) list of points.


You need a function to say whether one graph is a subgraph of another, a SubGraphQ function.

I recommend the IGraphM package, available at Look for the function IGSubisomorphicQ.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract