Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 11 Adjacency Matrix Graph Objective: Create a class which constructs an adja

ID: 3686296 • Letter: L

Question

Lab 11

Adjacency Matrix Graph

Objective:

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

Write an Adjacency Matrix Graph class which has the following:

Two constructors:

Default which makes the matrix of a pre-defined size

Parameterized which takes in a non-negative or 0 size and creates an empty matrix

addEdge: this method returns nothing and takes in two string parameters and a weight. The two integer parameters correspond to the names of vertices and the weight is the weight of the newly created edge.  

printDFS: This prints out the vertices name’s in depth first order. You can find the algorithm the presentation provided.

printBFS: This prints out the vertices name’s in breadth first order. Like above you can find the algorithm in the presentation.

printDFSForAll: For every vertex in the graph it will print its DFS

printBFSForAll: For every vertex in the graph it will print its BFS

Write another file that tests each of the methods for this graph.  

Explanation / Answer

Graph:

A graph consists of a set of nodes or vertices together with a set of edges or arcs where each edge joins two vertices. Unless otherwise specified, a graph is undirected: each edge is an unordered pair {u,v} of vertices, and we don't regard either of the two vertices as having a distinct role from the other. However, it is more common in computing to consider directed graphs or digraphs in which edges are ordered pairs (u,v); here the vertex u is the source of the edge and vertex v is the sink or target of the edge. Directed edges are usually drawn as arrows and undirected edges as curves or line segments.