Package org.graph4j.isomorphism
Class TreeIsomorphism
java.lang.Object
org.graph4j.isomorphism.TreeIsomorphism
- All Implemented Interfaces:
IsomorphismAlgorithm
Algorithm for testing isomorphism of undirected trees.
This algorithm is based on "Alfred V. Aho and John E. Hopcroft. 1974. The Design and Analysis of Computer Algorithms (1st ed.). Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.", page 83-84.
Time complexity: linear in the number of vertices of the input trees. Space complexity: linear in the number of vertices of the input trees.
- Author:
- Ignat Gabriel-Andrei, Cristian Frasinaru
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTreeIsomorphism(Graph tree1, Graph tree2) Constructor for the tree isomorphism algorithm. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.isomorphism.IsomorphismAlgorithm
checkTrivialConditions
-
Constructor Details
-
TreeIsomorphism
Constructor for the tree isomorphism algorithm. It does not verify if the input graphs are actually trees.- Parameters:
tree1- the first tree.tree2- the second tree.- Throws:
NullPointerException- if eithertree1ortree2isnull.IllegalArgumentException- if eithertree1ortree2is not undirected.
-
-
Method Details
-
areIsomorphic
public boolean areIsomorphic()Description copied from interface:IsomorphismAlgorithmChecks if the graphs are isomorphic.- Specified by:
areIsomorphicin interfaceIsomorphismAlgorithm- Returns:
trueif the graphs are isomorphic,falseotherwise.
-
findIsomorphism
Description copied from interface:IsomorphismAlgorithmFinds the isomorphic mapping between the first and the second graph.- Specified by:
findIsomorphismin interfaceIsomorphismAlgorithm- Returns:
- the isomorphism or
nullif the graphs are not isomorphic.
-
computeIsomorphic
protected boolean computeIsomorphic() -
getTree1
The first tree.- Returns:
- the first tree.
-
getTree2
The second tree.- Returns:
- the second tree.
-