Question
Write a method isValidBidiPath that accepts two parameters: a Graph , and a List of vertices representing a path, and returns true if that path
Write a method isValidBidiPath that accepts two parameters: a Graph
For example, if your method were passed given the graph below and the path [A, B, F, G], you would return true because all of those vertices are part of the graph and you can travel that path from A to G and back from G to A. If you were passed the same graph and the path [A, E, F, I], you would return false because that path does not go back from I to A. If you were passed the path [A, X, Z, B], you would return false because X and Z are not in the graph. You should not construct any auxiliary data structures while solving this problem, but you can construct as many simple variables as you like. You should not modify the state of the graph passed in. You may assume that the graph, the path, and the path's elements are not null.
A <---> B <---> C | ^ | | | | | | | v v v E ----> F <---> G | | | | | | v v H <---- I
The graph passed to your method implements the following interface:
public interface Graph{
public void addEdge(V v1, V v2);
public void addEdge(V v1, V v2, E e);
public void addEdge(V v1, V v2, int weight);
public void addEdge(V v1, V v2, E e, int weight);
public void addVertex(V v);
public void clear();
public void clearEdges();
public boolean containsEdge(E e);
public boolean containsEdge(V v1, V v2);
public boolean containsVertex(V v);
public int cost(Listpath);
public int degree(V v);
public E edge(V v1, V v2);
public int edgeCount();
public Collectionedges();
public int edgeWeight(V v1, V v2);
public int inDegree(V v);
public SetinverseNeighbors(V v);
public boolean isDirected();
public boolean isEmpty();
public boolean isReachable(V v1, V v2); // depth-first search
public boolean isWeighted();
public ListminimumWeightPath(V v1, V v2); // Dijkstra's algorithm
public Setneighbors(V v);
public int outDegree(V v);
public void removeEdge(E e);
public void removeEdge(V v1, V v2);
public void removeVertex(V v);
public ListshortestPath(V v1, V v2); // breadth-first search
public String toString();
public int vertexCount();
public Setvertices();
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started