The University of New South Wales - COMP9312 - 25T2 - Data Analytics for Graphs

Assignment 1

Graph Storage and Graph Traversal

Important updates for the assignment paper will be listed here.

[12-Jun 11:15 AM] Figure 3 is updated.

[15-Jun 11:15 AM] Updates for Q5 and Q6:

Q5: We consider a directed, unweighted graph G=(V, E) stored as an adjacency list.

Q6: We consider a weighted (positive weight), directed acyclic graph (DAG).

Summary

Submission Submit an electronic copy of all answers on Moodle (only the last submission will be used).
Required Files A .pdf file is required. The file name should be ass1_Zid.pdf
Deadline 9pm Friday 27 June (Sydney Time)
Marks 30 marks (15% toward your total mark for this course)

Late penalty. 5% of max mark will be deducted for each additional day (24hr) after the specified submission time and date. No submission is accepted 5 days (120hr) after the deadline.

START OF QUESTIONS
Figure 1
Figure 2
Figure 3

Q1. Required knowledge covered by Topic 1.1 (4 marks)

Please determine whether the following statements for the graph in Figure 1 are TRUE or FALSE.

  1. In some correct BFS traversal starting from v8, v13 can be traversed before v4.
  2. In some correct DFS traversal starting from v9, v5 can be traversed before v1.
  3. In any correct DFS traversal starting from v5, v7 must be traversed after v6.
  4. In any correct BFS traversal starting from v11, v12 must be traversed after v8.
  5. In any correct BFS traversal starting from v1, v4 must be traversed before v7.
  6. In any correct DFS traversal starting from v6, v1 must be traversed before v7.
  7. In some correct DFS traversal starting from v13, v7 can be traversed after v11.
  8. In some correct BFS traversal starting from v10, v1 can be traversed after v5.

Marking for Q1: 0.5 mark is given for each correct TRUE/FALSE answer.

Q2. Required knowledge covered by Topic 1.1 (5 marks)

Consider the undirected graph in Figure 2 stored by the adjacency list. For each vertex, the neighbors are arranged in ascending order of vertex ID (e.g., the neighbor list of v2 is [v3, v4]). Describe an algorithm to compute all connected components using the disjoint-set data structure. Show the tree structure after each union operation.

Marking for Q2: Full marks are given if each intermediate disjoint-set tree structure is correct.

Q3. Required knowledge covered by Topic 1.1 (5 marks)

Consider the directed graph in Figure 3 stored by the adjacency list. The neighbors of each vertex are arranged ascending order of vertex ID. Compute the topological order of vertices in the graph. Show intermediate steps.

Marking for Q3: Full marks are given if the described process of each vertex is correct and the order of vertices are correct.

Q4. Required knowledge covered by Topic 1.1 (5 marks)

Given an undirected graph G=(V, E) stored as an adjacency list , design an algorithm that determines whether the number of connected components will change if a specified edge is removed.

The input is:

You must not use disjoint-set to implement your algorithm. TWFrZSBzdXJlIHRvIHVzZSBhIHByaW9yaXR5IHF1ZXVlIGluIHlvdXIgaW1wbGVtZW50YXRpb24u

Your algorithm should return a Boolean value indicating whether removing the specified edge changes the number of connected components in the graph.

Provide pseudocode and analyze the time complexity of your solution.

Use n to denote the node count.
Use m to denote the edge count.

Example usage:

hasCcChanged(G, id1, id2) ➞ True
hasCcChanged(G, id1, id3) ➞ False

Marking for Q4: Two factors are evaluated in marking: (1) How good is your time complexity; (2) Does your algorithm match your time complexity. Full marks are given if your time complexity is not larger than our expected one and your algorithm corresponds with your time complexity.

Q5. Required knowledge covered by Topic 0 (5.5 marks)

We consider a directed, unweighted graph G=(V, E). Design a data structure that supports dynamic node insertion and deletion.

The data structure must support the following operations:

The type of id is assumed to be an integer.

Provide concise pseudocode for each operation and a clear time complexity analysis (worst case) for each operation and the space complexity of your data structure.

Use n to denote the current node count.
Use m to denote the current edge count.
Use N to denote the maximum node count ever present simultaneously.
Use M to denote the maximum edge count ever present simultaneously.
Use P to denote the number of times the addNode operation is called.
Use deg(v) to denote the degree of node v.

Example usage:

id1 = addNode()
id2 = addNode()
addNbr(id1, [id2])
getNeighbors(id1) ➞ [id2]
getNeighbors(id2) ➞ []
removeNode(id2)
getNeighbors(id1) ➞ []

Marking for Q5: Two factors are evaluated in marking: (1) How good is your time complexity and space complexity; (2) Does your algorithm match your time complexity; (3) Does your data structure match your space complexity. Full marks are given if your time complexity is not larger than our expected one and your algorithm corresponds with your time complexity.

Q6. Required knowledge covered by Topic 1.1 (5.5 marks)

Given a weighted (positive weight), directed acyclic graph (DAG) G=(V, E) stored as an adjacency list, and a pair of vertices s and t, design an algorithm to compute the shortest distance from s to t.

Your solution must not use priority queues.

Provide pseudocode and analyze the time complexity of your algorithm.

Use n to denote the node count.
Use m to denote the edge count.

Example usage:

shortestDistance(G, id1, id1) ➞ 0
shortestDistance(G, id1, id2) ➞ 10
shortestDistance(G, id1, id3) ➞ ∞

Marking for Q6: Two factors are evaluated in marking: (1) How good is your time complexity; (2) Does your algorithm match your time complexity. Full marks are given if your time complexity is not larger than our expected one and your algorithm corresponds with your time complexity.