The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+23 votes

Consider the directed graph below given. 

Which one of the following is TRUE?

  1. The graph does not have any topological ordering.
  2. Both PQRS and SRQP are topological orderings.
  3. Both PSRQ and SPRQ are topological orderings.
  4. PSRQ is the only topological ordering.
asked in Algorithms by Veteran (96.2k points)
edited by | 1.8k views

3 Answers

+22 votes
Best answer

The C option has been copied wrongly
        C. Both PSRQ and SPRQ are topological orderings

  1. Apply DFS by choosing P or S as starting vertices
  2. As the vertex gets a finishing time assign it to the head of a linked list
  3. The linked list is your required topological ordering
answered by (385 points)
edited by


I think, here  it ( should be used for getting all possible answer. 

In general for getting one possible answer, approach (DFS method ) proposed by you looks good. 


Topological Sort 


"The C option has been copied wrongly "

What is meaning of this line the above solution.

+22 votes

choose vertex in the graph which has 0 indegree . now see graph has such two vertices ie P,S so we can start topological sort either from vertex P or from S .

lets first start from vertex P now remove this vertex from graph ,we left with three vertices named asQ,S,R from these vertices see which vertex has INDEGREE 0,S vertex HAS indegree 0 therefore sequence is P,S,R,Q

repeat the above step from vertex S we get sequence as S,P,R,Q

answered by Boss (19.9k points)
edited by
Typo:- in first paragraph

"we can start totpological sort either from vertex P or from Q . "

It sud be P or from S
Nice explanation, Thanks
+6 votes
The graph doesn't contain any cycle, so there exist topological ordering. P and S must appear before R and Q because there are edges from P to R and Q, and from S to R and Q.

answer is c
answered by Loyal (9.3k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,576 questions
54,190 answers
71,147 users