Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 1.16 KB

ex08.md

File metadata and controls

40 lines (28 loc) · 1.16 KB

Exercise 08

Part A

Create a class AllPathsGraph that extends UndirectedGraph. In such class, create a method with the following signature:

public List<List<V>> findAllPaths(V start, V end)

Such method should return all possible paths from start to end that are not cyclic.

Write a test class called AllPathsGraphTest in which you recreate the graph shown in class in the slides, ie with edges:

graph.addEdge("0","X");
graph.addEdge("X","1");
graph.addEdge("X","Y");
graph.addEdge("1","2");
graph.addEdge("2","Y");
graph.addEdge("1","3");
graph.addEdge("3","4");
graph.addEdge("3","5");
graph.addEdge("4","5");

Call findAllPaths on such graph with input start=X and end=5. Verify that the method returns 4 paths, with lengths 4, 5, 6 and 7.

Part B

Study the source code of UndirectedGraph. Once you think you fully understand it, write its implementation on paper (e.g., using a pen), without looking at the source code. Once done, compare what you wrote with the actual implementation.

Solutions

Solutions to this exercise can be found in the solutions module, under the org.pg4200.sol08 package.