Question: Need a simple exercise with a graph based on an adjacency list. provide two method implementations for the following class: import java . util .

Need a simple exercise with a graph based on an adjacency list. provide two method implementations for the following class:

import java . util . Map ; import java . util . Set ; import java . util . List ; public class Graph { public Graph () { adjacency = new java . util . HashMap < >(); } public void addEdge (T start , T end ) { } public boolean testPath ( List vertexList ) { } private Map > adjacency ; }

the following methods are needed: 1. void addEdge(T start, T end) This code adds the directed edge (start, end) to the graph. In the map adjacency, get or create the Set associated with start, and add end to this Set. 2. boolean testPath(List vertexList) This method should return true if each consecutive pair of vertices in the list exists in the graph, false otherwise. Throw an exception if vertexList doesnt have at least one edges worth of vertices in it!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!