43 43 votes Consider the directed graph below given. Which one of the following is TRUE? The graph does not have any topological ordering. Both PQRS and SRQP are topological orderings. Both PSRQ and SPRQ are topological orderings. PSRQ is the only topological ordering. Algorithms gatecse-2014-set1 graph-algorithms easy topological-sort + – go_editor 11.9k views answer comment Share Follow Print See 1 comment 1 1 comment reply Hussain9660 commented Nov 7, 2024 reply Follow flag The answer is clearly option C. This is because S and P dont have any prerequisites i.e. no incoming edges so they can be visited in any order but before R and Q as these edges are dependent on P and S. Also Q should be visited after R only. Hence both PSRQ and SPRQ are the correct answers. 1 1 replyShare Please log in or register to add a comment.
Best answer 43 43 votes C. Both PSRQ and SPRQ are topological orderings Apply DFS by choosing P or S as starting vertices As the vertex gets a finishing time assign it to the head of a linked list The linked list is your required topological ordering Akshay Jindal answered Sep 27, 2014 • edited Oct 27, 2017 by kenzou Akshay Jindal comment Share Follow See all 2 Comments 2 2 Comments reply Chhotu commented Aug 23, 2017 reply Follow flag Hi, I think, here it (http://www.geeksforgeeks.org/all-topological-sorts-of-a-directed-acyclic-graph/) should be used for getting all possible answer. In general for getting one possible answer, approach (DFS method ) proposed by you looks good. 8 8 replyShare Adarsh Nipun commented Sep 10, 2020 reply Follow flag P and S does not have any indirect edges connecting through vertices. So, order of p and s does not matter. C is the answer 0 0 replyShare Please log in or register to add a comment.
40 40 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 focus _GATE answered Jul 22, 2015 • edited Jan 8, 2018 by Puja Mishra focus _GATE comment Share Follow See all 2 Comments 2 2 Comments reply Rajesh Pradhan commented Sep 23, 2016 reply Follow flag Typo:- in first paragraph "we can start totpological sort either from vertex P or from Q . " It sud be P or from S 0 0 replyShare Sanjay Mahaveer commented Sep 30, 2018 reply Follow flag Nice explanation, Thanks 0 0 replyShare Please log in or register to add a comment.
8 8 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 Regina Phalange answered Apr 6, 2017 Regina Phalange comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes There are no cycles in the graph, so topological orderings do exist. We can consider P & S as starting vertex, followed by R & Q. Hence, PSRQ & SPRQ are the topological orderings. varunrajarathnam answered Aug 7, 2020 varunrajarathnam comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Think of edges as courses. If an edge is there between two courses as C1->C2, then C1 is prerequisite for C2. Ankit Kabi answered Oct 29, 2020 Ankit Kabi comment Share Follow 0 reply Please log in or register to add a comment.