Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP108 Data Structures and Algorithms

Lab Exercises (Week 8)

Information

● Submission: Submit the file COMP108W08.java to SAM https://sam.csc.liv.ac.uk/COMP/CW Submissions.pl?qryAssignment=COMP108-18

Late submission is only accepted until Monday 9:00am.

● Submission of lab/tutorial exercises contributes to 10% of the overall module mark. Submission is marked on a pass/fail basis - you will get full marks for submitting a reasonable attempt.

● Individual feedback will not be given, but solutions will be posted promptly after the deadline has passed.

● These exercises aim to give you practices on the materials taught during lectures and provide guidance towards assignments.

● Relevant lectures: Lecture 19

● You can refer to the guidance on how to use the web-based IDE https://ide.cs50.io/.

1. Programming — Preparation

(a) Download three java files “COMP108W08App.java”, “COMP108W08.java” from Canvas

via the link “Labs & Tutorials” → “Week 8”.

(b)  Compile the programs by typing first javac COMP108W08.java and then

javac COMP108W08App.java. There should be two files created: COMP108W08.class and COMP108W08App.class.

(c) Run the program by typing java COMP108W08App

(d) Every time you have edited COMP108W08.java, you have to (i) recompile by javac COMP108W08.java and then (ii) run by java COMP108W08App.

2.  Graph This week we will work with graph.

● An adjacency matrix represents a graph by representing the edges between vertices.

● An entry of the adjacency matrix M[i][j] is 1 if vertex i and vertex j have an edge between them and 0 otherwise.

3. Task 1:  Degree of a graph.  In COMP108W08.java, the method findDegree() is expected to find the degree of the graph, which is the maximum degree of the vertices and the degree of a vertex is the number of neighbours it has.  The method takes in as parameter a two dimensional array adjMatrix[][] for the adjacency matrix and an integer gSize for the size of the graph (number of vertices).

Complete the method (without changing its signature) and test it using test cases stated at the end of the document.

4. Task 2: Distance between two vertices. The method distance() is expected to determine for two vertices if v1 and v2 are at distance 1, distance 2, or not connected at distance 2.