Project 1: Graph Isomorphism

Due Date: Sep 27, 2018


Background

Two (undirected, simple) 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’?

Your Task

For this assignment, you are to write a program 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.

Input/Output Format

You have to read the 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 is the number of vertices of each graph. It is 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
    000
    000
    000
    010
    100
    000

your answer should be “not isomorphic” and for the input

    3
    010
    100
    000
    001
    000
    100

your answer should be “isomorphic.”

Testing

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 strategies for speeding up your program in class. I recommend backtracking. You can take a look at my backtracking programs for the N-Queen puzzle as examples. Here are the programs in Kotlin and Python. Your grade will be based on the number of my test files that your program can solve correctly and your program’s running time.

Submission

See programming-guidelines.