Question: Lab Task 0 3 : Complete the Graph.java method: private boolean isReachable ( int src , int dest, boolean [ ] visited ) in the
Lab Task :
Complete the Graph.java method: private boolean isReachableint src int dest, boolean visited in the
folder Task such that it returns true if the destination vertex dest is reachable from the source vertex src;
otherwise, it returns false.
Complete the test program to prompt for and read the source and destination vertices. It then checks whether the
destination vertex is reachable from the source vertex. Note: Assume that the values read are valid.
import java.util.List;
import java.util.ArrayList;
import java.util.Queue;
import java.util.ArrayDeque;
Determines if a vertex is reachable from another vertex in a directed graph
public class Graph
private List adjList null;
private int numVertices;
public GraphList edges, int numVertices
this.numVertices numVertices;
adjList new ArrayList;
for int i ; i numVertices; i
adjList.addnew ArrayList;
add edges to the directed graph
for Edge edge: edges
int src edge.source;
int dest edge.dest;
adjList.getsrcadddest;
public boolean isReachableint src int dest
boolean visited new booleannumVertices;
return isReachablesrc dest, visited;
Function to perform BFS traversal from the source vertex in the graph to
determine if the destination vertex is reachable from the source or not
private boolean isReachableint src int dest, boolean visited
to be completed by students
public class Edge
public int source, dest;
private Edgeint source, int dest
this.source source;
this.dest dest;
public static Edge getEdgeint a int b
return new Edgea b; calls private constructor
import java.util.List;
import java.util.Arrays;
import java.util.Scanner;
public class GraphDriver
public static void mainString args
Scanner scanner new ScannerSystemin;
List edges Arrays.asListEdgegetEdge Edge.getEdge
Edge.getEdge Edge.getEdge
Edge.getEdge Edge.getEdge
Edge.getEdge Edge.getEdge
Edge.getEdge Edge.getEdge
Edge.getEdge;
Number of nodes in the graph labelled from to N
int numVertices ;
To be completed by students
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
