Data Structures and Information - Practical Assignment I

Assessed Practical

Introduction

In Lecture 4 one of the standard data structures for representing Undirected Graphs was presented.

One weakness of the technique used, is that a 2-dimensional array is not an efficient way to hold details about graphs which do not have `many' edges, (so-called sparse graphs),

In order to overcome some of the problems with the adjacency matrix representation (as the technique used in Lecture 4 is known), an alternative approach (called incidence list representation) can be used.

For the graph,

The adjacency matrix (2-D array) form would be:

12345
10011
2111
311
40

whereas the incidence list form would be:

So if G(V,E) is an n-vertex undirected graph with vertex set

V = { 1, 2, 3, ... , n }

The incidence list representation of G(V,E) uses:

An array of n-1 Linked Lists.

(One linked list for each of the vertices v such that 1< = v < n.)

The linked list for vertex k has one list cell for each vertex, w for which:

there is an edge between vertex k and vertex w with w > k.

(if there are no such edges the corresponding linked list is empty).

Requirements

Design, implement and test a Java Class, SparseGraph, whose Class Diagram is

Description

Class Fields

Constructors

Instance Methods

What you should hand in

You should hand in to your Group Tutor:

  1. A description of the exercise Requirements
  2. Details of the design of your solution.
  3. The source code for the SparseGraph class implementation.
  4. Information regarding the test data and harness for your implementation:

    1. The design of the test harness.
    2. The data used to test the implementation.
    3. The output from your testing.

Notes

  1. In constructing the test harness for your implementation you should ensure that each Constructor and each Instance method is tested.
  2. You may find it helpful to use the int input methods to be found here. This provides a class method

    public static intget_int (BufferedReader instream )

    that will read a sequence of digits (stopping at a `whitespace' character) and return the integer value that has been read.

  3. It is very easy to mis-type graph data (particularly if the graph has a large number of vertices), so you should try to prepare the test data in a separate file. For example, a 10 vertex graph could be
    
    0 1 1 0 1 1 0 1 1 0
    1 0 0 0 0 1 0 0 1 1
    1 0 0 1 0 1 0 0 0 1
    0 0 1 0 0 0 1 1 0 1
    1 0 0 0 0 1 0 0 0 0
    1 1 1 0 1 0 1 0 1 0
    0 0 0 1 0 1 0 0 0 0
    1 0 0 1 0 0 0 0 0 1
    1 1 0 0 0 1 0 0 0 1
    0 1 1 1 0 0 0 1 1 0
    
    

Your completed work should be handed in to your group tutor at your practical class on Thursday 24th February