Implementation of SearchImp of this labsheet is worth 2.5% of your final mark in this unit. The final date for submission is: 11:59pm Friday, April 28, 2023.
The aims of this labsheet are to:
implement a bredth first search of a graph, and apply it to find distances of vertices from a specified source.
implement a depth first search of a directed graph and apply it to finding the start times and finish times of vertices.
Search
is provided and you should implement it as a class SearchImp
. You should complete the following methods:
getConnectedTree
should output an array specifying the parent vertex for each vertex (or -1 if there is no parent), assuming a Breadth First Search.getDistances
should output an array specifying the distance each vertex is from the starting vertex, or -1 if it is not reachable.getTimes
you should, assuming a depth first search, output the start and finish times for each vertex. Given that the graph G has n vertices, the method getTimes(G,S)
should return an n × 2 array of integers. For example. if a = getTimes(G,S)
then the start time for vertex i is a[i][0] and the end time for vertex i is a[i][1].
javadoc
comments.
Submit your SearchImp
implementation to Moodle.
If submitted before the due date, the system will compile and run your code, estimate your mark, and provide you with feedback. Final marking will occur after the posted due date and is subject to further examination, testing, and plagiarism checks of your code. Note that for security reasons, your code cannot contain any I/O commands, including printing statements. Although the auto-marking program provides you with some feedback, it should not be used as a substitute for your own testing.
Sample solution for Lab6 is here