Skip to content

Commit 6be26f5

Browse files
committed
Tree isomorphism testing
1 parent a4cea71 commit 6be26f5

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphismWithBfs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* <p>http://webhome.cs.uvic.ca/~wendym/courses/582/16/notes/582_12_tree_can_form.pdf
77
*
8-
* This implementation uses a breadth first search on an undirected graph to generate the tree's
8+
* <p>This implementation uses a breadth first search on an undirected graph to generate the tree's
99
* canonical encoding.
1010
*
1111
* <p>Tested code against: https://uva.onlinejudge.org/external/124/p12489.pdf

javatests/com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphismTest.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.addUndirectedEdge;
1010
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.createGraph;
1111
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.treesAreIsomorphic;
12-
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphism.TreeNode;
1312

1413
import java.util.*;
1514
import org.junit.*;
@@ -135,7 +134,9 @@ public void testIsomorphismEquivilanceAgainstOtherImpl() {
135134
List<List<Integer>> tree2 = generateRandomTree(n);
136135

137136
boolean impl1 = treesAreIsomorphic(tree1, tree2);
138-
boolean impl2 = com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.treesAreIsomorphic(tree1, tree2);
137+
boolean impl2 =
138+
com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs
139+
.treesAreIsomorphic(tree1, tree2);
139140
if (impl1 != impl2) {
140141
System.err.println("TreeIsomorphism algorithms disagree!");
141142
System.err.println(tree1);
@@ -148,29 +149,14 @@ public void testIsomorphismEquivilanceAgainstOtherImpl() {
148149

149150
public static List<List<Integer>> generateRandomTree(int n) {
150151
List<Integer> nodes = new ArrayList<>();
151-
nodes.add(0);
152+
nodes.add(0);
152153

153154
List<List<Integer>> g = createGraph(n);
154-
for(int nextNode = 1; nodes.size() != n; nextNode++) {
155-
int randomNode = nodes.get((int)(Math.random() * nodes.size()));
155+
for (int nextNode = 1; nodes.size() != n; nextNode++) {
156+
int randomNode = nodes.get((int) (Math.random() * nodes.size()));
156157
addUndirectedEdge(g, randomNode, nextNode);
157158
nodes.add(nextNode);
158159
}
159160
return g;
160161
}
161162
}
162-
163-
164-
165-
166-
167-
168-
169-
170-
171-
172-
173-
174-
175-
176-

javatests/com/williamfiset/algorithms/graphtheory/treealgorithms/TreeIsomorphismWithBfsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import static com.google.common.truth.Truth.assertThat;
44
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.addUndirectedEdge;
55
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.createEmptyTree;
6-
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.treesAreIsomorphic;
76
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.encodeTree;
7+
import static com.williamfiset.algorithms.graphtheory.treealgorithms.TreeIsomorphismWithBfs.treesAreIsomorphic;
88

99
import java.util.*;
1010
import org.junit.*;

0 commit comments

Comments
 (0)