QUESTION 13
What is a graph?
2 marksAnswer
A graph G = (V, E) consists of vertices and edges describing relationships. Edges may be directed or undirected according to the model.
QUESTION 13
A graph G = (V, E) consists of vertices and edges describing relationships. Edges may be directed or undirected according to the model.
QUESTION 14
Graphs represent general connections rather than a single rooted hierarchy.
Adjacent vertices share a suitable edge. A path follows successive edges. A cycle returns to its starting vertex through the stated path convention. In an undirected graph, degree counts incident edges with loops treated by the chosen convention. A directed graph separates in-degree and out-degree.
Cities can be vertices and flights directed edges. A flight from city 2 to city 3 does not imply a return flight unless a separate edge is supplied. If time or price matters, store it as a weight with a defined meaning.
A finite connected undirected acyclic graph is a tree. A graph in general can contain cycles and disconnected components. Traversal therefore needs a visited record; merely following neighbours without one can revisit vertices indefinitely.
The representation controls adjacency tests and neighbour enumeration. An adjacency matrix uses O(V²) space, while adjacency lists use O(V + E) space for the usual representation. The ADT should specify edge direction, duplicate-edge and weight rules.
The following are topic matches from the supplied papers. Marks are their printed allocations, separate from the practice answer badge.
Define a graph.
Paper DS03 · page 1