Skip to content
Related Articles

Related Articles

GATE | GATE-CS-2001 | Question 24

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

Suppose the adjacency relation of vertices in a graph is represented in a table Adj(X,Y). Which of the following queries cannot be expressed by a relational algebra expression of constant length?
(A) List of all vertices adjacent to a given vertex
(B) List all vertices which have self loops
(C) List all vertices which belong to cycles of less than three vertices
(D) List all vertices reachable from a given vertex


Answer: (D)

Explanation: (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

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!