Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use java programming language 1) Implement a graph ADT by defining a class Graph with the operations below. Your ADT should accept either a directed

use java programming language

1) Implement a graph ADT by defining a class Graph with the operations below. Your ADT should accept either a directed or undirected graph. isDirect(): tests if the graph is a digraph. Returns Boolean value. adjacent(v, u): tests whether there is an edge from the vertex v to u. returns a Boolean value. neighbors(v): returns the list of all vertices that are a destination of an edge from v. addVertex(v): adds the vertex v to the graph if it is not already in the graph, otherwise an error message to be thrown. removeVertex(v): removes vertex v from the graph, if it is there. When a vertex is removed, all edges associated with that vertex should be deleted as well. addEdge(v, u): adds the edge that starts from v and ends at u. addEdge(v, u, w): adds the edge that starts from v and ends at u with weight w. removeEdge(v, u): remove the edge that connects v and u. getWeight(v, u): returns the weight of the edge from v to u. setWeight(v, u): sets the weight of the edge from v to u. isEmpty(): check whether the graph is empty or not. isComplete(): checks whether the graph is complete or not. vertices(): returns the list of vertices in the graph (i.e., array, vector,..) edges(): returns the list of edges in the graph. degree(v): return the degree of vertex v. size(): returns the number of vertices in the graph. nEdges(): returns the number of edges in the graph. clear(): Reinitializes the graph to be empty, freeing any heap storage. vertexExists(v): tests whether a vertex is in the graph or not. Returns true or false. print(): displays the list of vertices, edges and their weights if the graph is weighted. Your ADT should contain at least these constructors: Graph(), creates a graph with zero vertices. Graph(n), creates a graph with n vertices. Graph(n, digraph), where digraph is a Boolean value if true means a directed graph.

2). Write a main method that reads graph.txt file which contains the information of a directed weighted graph. The file is formatted as the following:

First line is the number of vertices in the graph. Second line contains the vertices in the graph. Each following line contains the edges and the weights. For example: a b 4, means an edge from a to be with weight = 4.

After reading the file and creating the graph perform the following operations in the same order:

removeVertex(h)

print if the graph is complete or not (i.e., the graph is complete or the graph is not complete)

print number of edges in the graph (i.e., number of edges is xx)

print if there is a link from a to f (i.e., there is a link from a to f or there is no link from a to f)

print the weight of the edge bh (i.e., the weight of the edge from b to h is xx)

print the degree of c (i.e., the degree of c is xx)

print number of vertices in the graph (i.e., the graph contains xx vertices)

graph.txt file as follow:

8 a b c d e f g h a b 1 a c 3 b g 2 b h 5 c d 4 c f 2 d e 3 e c 6 e a 2 f b 3 g h 1 g e 1 h b 2

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago