Homework 2

Due Date: Oct 2, 2014

Two (undirected) graphs G = (V, E) and G' = (V', E') are isomorphic if and only if there exists a 1-1 and onto function φ : V → V' such that for all vertices v and w of G, (v,w) is an edge in E if and only if (φ(v), φ(w)) is an edge in E'.

The Graph Isomorphism Problem is as follows.

Instance: Graphs G = (V, E) and G' = (V', E').
Question: Is G isomorphic to G'?

For this assignment, you are to write a program in either python or Java to solve the Graph Isomorphism Problem. The graphs should be input as adjacency matrices. The output can simply by "isomorphic" or "not isomorphic" as the case may be. I suggest you read input graphs from standard input and write your answer to the standard output. You may assume the two input graphs have the same number of vertices. The first input number should be the number of vertices of each graph. This should be followed by the adjacency matrix for the first graph, then followed by the adjacency matrix for the second graph. For example, for the input

3
0 0 0
0 0 0
0 0 0
0 1 0
1 0 0
0 0 0
your answer should be "not isomorphic" and for the input
3
0 1 0
1 0 0
0 0 0
0 0 1
0 0 0
1 0 0
your answer should be "isomorphic." You may assume correct input. There's no need to write code to check whether the input is valid or not.

Make sure your program can solve the input files testFile1 and testFile2 correctly within a reasonable amount of time. I'm going to use larger test files when grading, so make your program run as fast as possible. We'll discuss various strategies for doing so in class. I suggest using backtracking. (You can look at my backtracking algorithm in python for the N-Queen puzzle as an example.) Your grade will be based on the number of my test files that your program can solve and your program's running time.

Submit your source program, input files, and README file by bundling them up in a zip file and emailing it to me. The README file should describe those aspects of your program that are not obvious from the source code. For example, how to run the program, the tests files you used, etc.