Suppose the adjacency relation of vertices in a graph is represented in a table Adj Which of the following queries cannot be expressed by a relational algebra expression of constant length?
View worked solution
Answer: D
To determine which query cannot be expressed by a relational algebra (RA) expression of constant length, let's analyze each option:
- Option A: List all vertices adjacent to a given vertex
This requires a simple selection and projection: This is of constant length. - Option B: List all vertices which have self-loops
A self-loop occurs when a vertex is adjacent to itself (): This is of constant length. - Option C: List all vertices which belong to cycles of less than three vertices
Cycles of length less than 3 can only be of length 1 (self-loops) or length 2 (where and with ).- Cycles of length 1: .
- Cycles of length 2: .
- Option D: List all vertices reachable from a given vertex
Finding all reachable vertices in an arbitrary graph requires computing the transitive closure of the adjacency relation. Since the number of vertices is not fixed, the path length can be arbitrarily large. Standard relational algebra lacks recursion or looping constructs, meaning we cannot write a single, fixed-length expression to compute transitive closure for graphs of arbitrary size.
Therefore, reachability (Option D) cannot be expressed by a relational algebra expression of constant length.
Free practice · Your answers on this page are not saved.
