Lab 09

Adjacency Matrix Graph

 

Objective:

 

Create a class which constructs an adjacency matrix representation of a graph and performs a few graph operations.

 

Lab Solution

 

Requirements:

 

 

 

The provided tester uses the following Graph for reference.

 

 

Example Dialog:

*The following Example Dialog demonstrates the interactions between a user and ONE possible implementation of the required software’s front-end / user interface. The software’s front-end / user interface may be implemented in MANY different ways and will receive full credit as long as it meets the most minimal of the above requirements. While you may use the example dialog as a guide, it is strongly encouraged to create the front-end / user interface in your own way. *

Key

Unhighlighted Text

Program’s Output

Highlighted Text

User’s Input

 

-------------------------------------

TEST: Making graph with 7 Vertices

-------------------------------------

Graph is not null? true

-------------------------------------

TEST: Adding edges

-------------------------------------

10 Edges have been added.

-------------------------------------

TEST: Print ADJMatrix

-------------------------------------

0.0 1.0 0.0 1.0 0.0 0.0 0.0

0.0 0.0 0.0 1.0 0.0 0.0 0.0

1.0 0.0 0.0 0.0 1.0 1.0 0.0

0.0 0.0 1.0 0.0 1.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 1.0 1.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0

-------------------------------------

TEST: Print DFS from Vertex 1 (index 0)

-------------------------------------

0

1

3

2

4

5

6

-------------------------------------

TEST: Print BFS from Vertex 1 (index 0)

-------------------------------------

0

1

3

2

4

5

6

-------------------------------------

TEST: Print DFS from Vertex 5 (index 4)

-------------------------------------

4

5

6

-------------------------------------

TEST: Printing BFS from Vertex 3 (index 2)

-------------------------------------

2

0

4

5

1

3

6

 

 

 

 

 

Lab Report Questions:

  1. Create a section named “Problem” and describe this lab’s problem in your own words. (10pts).
  2. Create a section named “Solution Description” and describe how the code solves the problem in your own words. (10pts).
  3. Create a section named “Problems Encountered” and describe the various syntax, run-time, and logic errors that were encountered while implementing the solution. (10pts).
  4. Describe the process of DFS in your own words. (10pts).
  5. Describe the process of BFS in your own words. (10pts).

 

  1. Using the above graph, create a corresponding adjacency matrix. Assume the rows are “from” vertices and the columns are “to” vertices.
  2. Using the above graph, describe the DFS starting from vertex “v5”. This must include all uniquely visited vertices (no duplicates) in DFS order. Ties are broken based on the lesser of the two values (IE Vertex 2 is visited before Vertex 4).
  3. Using the above graph, describe the BFS starting from vertex “v5”. This must include all uniquely visited vertices (no duplicates) in BFS order. Ties are broken based on the lesser of the two values (IE Vertex 2 is visited before Vertex 4).
  4. Using the above graph, describe the DFS starting from vertex “v2”. This must include all uniquely visited vertices (no duplicates) in DFS order. Ties are broken based on the lesser of the two values (IE Vertex 2 is visited before Vertex 4).
  5. Using the above graph, describe the BFS starting from vertex “v2”. This must include all uniquely visited vertices (no duplicates) in BFS order. Ties are broken based on the lesser of the two values (IE Vertex 2 is visited before Vertex 4).

 

 

 

Finally: