QUESTION 23
Name operations of a basic graph ADT.
2 marksAnswer
Create a graph, add or remove vertices or edges, test adjacency, enumerate neighbours and traverse according to the chosen graph model.
QUESTION 23
Create a graph, add or remove vertices or edges, test adjacency, enumerate neighbours and traverse according to the chosen graph model.
QUESTION 24
A graph ADT specifies vertices, edge relationships and permitted operations independently of a matrix or list implementation.
State whether vertices have fixed indices or external labels, whether edges are directed, and whether weights or duplicate edges are allowed. Define error results for invalid vertices and how a missing edge is represented.
A fixed matrix provides direct adjacency tests and simple bounds checks for a small graph. Adjacency lists store only present edges and suit sparse neighbour traversal. Removing a vertex requires updating incident edges and any index mapping; it is not just deleting one display label.
An edge should represent a well-defined relation. Friendship may be undirected while following an account may be directed. Travel distance and fare are different weights. A DFS or BFS traversal answers reachability questions, but a particular application may require additional algorithmic steps.
The ADT alone does not promise every operation is constant time. In a matrix, a valid edge lookup is O(1); a whole neighbour row scan is O(V). Lists have degree-based scans and O(V + E) storage. Separate the logical contract from the chosen performance characteristics.