Design and implement a Java DiGraph class which provides the following public methods:
For the graph below, the method will return false. If we added an edge from Boston to London, for example, it would return true because this creates a path (London, New York), (New York, Boston), (Boston, London) from London to itself.
Moscow <---- London -----> Paris | ^ | | | | v | New York ----> Bostonshould be printed as follows (the order of nodes not essential):
Moscow --> London --> Moscow, Paris, New York Paris --> New York --> Boston Boston --> Paris
You may assume that the Objects used as node labels implement the Comparable interface and that the natural ordering is consistent with equals() if you need this for your implementation (for example, if you want to maintain an ordered list of nodes).
Any complete, correct and well-explained solution will get a mark of at least 60. To get a higher mark, you need to provide an efficient implementation of the loops() method.
To test your program for correctness, you can use the following simple menu-driven test called SimpleTest.java (this will also tell you if your method signatures are not what my testing program assumes). Suggestions for efficiency testing will be published next week. Basically, very large graphs (hundreds of thousands of nodes) will be generated using integer arrays (to make node labels out of integers, Integer objects will be created). The graph will be modified using addEdge(Object x, Object y) and removeEdge(Object x, Object y) methods and loops() method is going to be called after each modification.
The submission consists of two parts:
Submissions are due at 5pm on Thursday the 27th of November and will be collected electronically from the subdirectory coursework/g5bads of your Private directory (e.g., if your username is abc02u, then the files will be collected from the directory /stud/ug/abc02u/Private/coursework/g5bads).Please ensure that the capitalisation and spelling of your submission directory is correct, otherwise your submission will not be collected. You will be notified by email when your submission has been successfully collected. If you don't receive confirmation by the 28th of November, please contact me. Submissions which are not collected due to incorrect spelling etc. will incur 5% penalty. Submissions which are one working day late will be penalised 5%, two working days late 10% and so on (unless your tutor writes to me supporting a request for extension).
There will be a prize for the best solution.You are reminded of the School's Policy on Plagiarism.