Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Graph3 {private boolean adjMatrix[][]; private int numVertices; public Graph3(int numVertices) { } // Add edges public void addEdge(int i, int j) { adjMatrix[i][j]

public class Graph3 {private boolean adjMatrix[][]; private int numVertices; public Graph3(int numVertices) { } // Add edges public void addEdge(int i, int j) { adjMatrix[i][j] = true; adjMatrix[j][i] = true; } // Print the matrix public String toString() { StringBuilder s = new StringBuilder(); for (int i = 0; i < numVertices; i++) { s.append(i + ": "); // Adding the vertices { s.append((j ? 1 : 0) + " "); } s.append(" "); } return s.toString(); } public static void main(String args[]) { Graph3 g = new Graph3(5); g.addEdge(0, 1); g.addEdge(0, 4); g.addEdge(1, 0); g.addEdge(1, 4); g.addEdge(1, 3); g.addEdge(3,2); g.addEdge(3,4); g.addEdge(4, 0); g.addEdge(4, 1); g.addEdge(4,3); System.out.print(g.toString()); } }

The code template for the assignment is provided above. A few coding statements are missing, You will fill in these statements and code for representing a graph through the adjacent Matrix. Your graph will have 6 vertices and 7 edges.

You can choose which edge will connect which vertex.

You will also draw the graph.

Your code should have annotations

Take the screenshots of your code, outputs, and diagram of your graph convert them into pdfs and upload them here.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions