Math 3614, Homework 2

Instructions: The following problems are due on Monday 10/21/96 at the beginning of class. You may discuss the problems with other students in the class, but any work you turn in must be your own.

  1. Chapter 7 Supplementary Exercises: 17,18

  2. Programming Assignment: (See the handout Guidelines for programming assignments for instructions concerning programming assignments).

    Write a program that will determine the diameter of a graph after computing the distance between each pair of vertices. The distance is the length of a shortest path from one vertex to another (if there is not path connecting two vertices, then the distance between them is infinity). The diameter is the maximum distance between any pair of vertices in the graph. Note: The diameter of a disconnected graph is infinity. Input will be the number of vertices in the graph (allow for a maximum of fifteen) and an adjacency list; output will be a list of vertex pairs, their distances, and then the diameter of the graph. Input should look something like:

    How many vertices in the graph?
    >> 5
    Using the form "a,b", enter the endpoints of each edge. Type -1 to quit.
    >> 1,2
    >> 2,3
    >> 3,4
    >> 4,5
    >> -1

    Output should look something like:

    Vertex Pair Distance
    (1,2) 1
    (1,3) 2
    (1,4) 3
    (1,5) 4
    (2,3) 1
    (2,4) 2
    (2,5) 3
    (3,4) 1
    (3,5) 2
    (4,5) 1
    The diameter of the graph is 4.

    If there is not a path connecting two vertices, you should output a distance of "inf". Similarly, if the graph is disconnected, you should output a diameter of "inf". You should run your program on three different data sets:

    1. 5 vertices, with edges (1,2), (2,3), (3,4), (4,5).
    2. 4 vertices, with edges (1,2), (3,4)
    3. The 3-cube Q_3 (See example 7, page 441).