Exercise 1a of this labsheet is worth 2.5% of your final mark in this unit. The final date for submission is: 11:59pm Friday, May 8 2020.
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.
Searchis provided and you should implement it as a class
SearchImp. You should complete the following methods:
getConnectedTreeshould output an array specifying the parent vertex for each vertex (or -1 if there is no parent), assuming a Breadth First Search.
getDistancesshould output an array specifying the distance each vertex is from the starting vertex, or -1 if it is not reachable.
getTimesyou 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] and the end time for vertex i is a[i].
SearchImp implementation to cssubmit.
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.