Suppose the adjacency relation of vertices in a graph is represented i...
(A) This is simple query as we need to find (X, Y) for a given X. (B) This is also simple as need to find (X, X) (C) :-> Cycle < 3 . Means cycle of length 1 & 2. Cycle of length 1 is easy., Same as self loop. Cycle of length 2 is is also not too hard to compute. Though it'll be little complex, will need to do like (X,Y) & (Y, X ) both present & X != Y,. We can do this with constant RA query. (D) :-> This is most hard part. Here we need to find closure of vertices. This will need kind of loop. If the graph is like skewed tree, our query must loop for O(N) Times. We can't do with constant length query here. Answer is :-> D
View all questions of this test
Suppose the adjacency relation of vertices in a graph is represented i...
Explanation:
The relational algebra is a formal language for querying and manipulating relational databases. It consists of a set of operators that can be used to perform various operations on relations or tables.
In this question, we are given a table Adj(X,Y) which represents the adjacency relation between vertices in a graph. We need to determine which of the given queries cannot be expressed by a relational algebra expression of constant length.
Let's analyze each option one by one:
a) List of all vertices adjacent to a given vertex:
This query can be expressed using a selection operation in relational algebra. We can select all rows from the table where the given vertex is in the X column and retrieve the corresponding vertices from the Y column. This can be represented as: σ(X = given_vertex) (Adj(X,Y))
b) List all vertices which have self loops:
This query can be expressed using a selection operation in relational algebra. We can select all rows from the table where the X and Y columns have the same value, indicating a self-loop. This can be represented as: σ(X = Y) (Adj(X,Y))
c) List all vertices which belong to cycles of less than three vertices:
This query can be expressed using a self-join operation in relational algebra. We can join the table with itself, matching vertices from the X column to vertices in the Y column. Then, we can select all rows where the joined vertices are the same and retrieve the corresponding vertices from the X column. This can be represented as: π(X) (σ(X = Y) (Adj(X,Y) ⨝ Adj(X,Y)))
d) List all vertices reachable from a given vertex:
This query cannot be expressed by a relational algebra expression of constant length. It requires a recursive operation to traverse the graph and find all reachable vertices from the given vertex. Relational algebra does not have a built-in operator to handle recursion, so this query cannot be expressed using a constant length expression.
Therefore, the correct answer is option 'D' - List all vertices reachable from a given vertex.