edited by
252 views
1 votes
1 votes



Which one of the following is a topological sort for the above graph?

  1. $1, 6, 2, 5, 3, 4$
  2. $4, 5, 6, 3, 2, 1$
  3. $2, 4, 5, 6, 3, 1$
  4. $6, 4, 5, 2, 1, 3$
edited by

2 Answers

Best answer
1 votes
1 votes

We can start either from vertex 4 or from vertex 6 because only these 2 have no incoming edge.

Therefore option B , D will be considered 

Starting from vertex 4, next vertex can be 5 or 6.(order: 4)

considering vertex 5, next vertex can be 2 or 6 (order: 4,5)             |    considering vertex 6, next vertex can be 5.(order:4,6)

considering vertex 6, next vertex can be 2(order: 4,5,6)                   |    considering vertex 5, next vertex will be 2.(order:4,6,5)

                               or                                                                                 |    considering vertex 2, next vertex can be 1,3(order:4,6,5,2)

considering vertex 2,next vertex can be 6(order:4,5,2)                     |  finally correct order can be (4,6,5,2,3,1) or (4,6,5,2,1,3)

considering order 4,5,6 next vertex 2: order(4,5,6,2)                        | no option

considering order 4,5,2, next vertex 6 : order (4,5,2,6)                     |

considering order(4,5,6,2)or(4,5,2,6) ,next vertex can be 1,3           |

finally correct order can be (4,5,6,2,1,3) or (4,5,6,2,3,1) or (4,5,2,6,1,3),(4,5,2,6,3,1)----------no option

therefore option B is wrong


Starting from vertex 6, next vertex will be 4.(order: 6)

considering vertex 4, next vertex will be 5.(order: 6,4)

considering vertex 5, next vertex will be 2.(order: 6,4,5)

considering vertex 2, next vertex can be 1,3.(order: 6,4,5,2)

finally correct order can be (6,4,5,2,1,3) or  (6,4,5,2,3,1)

The correct ans is option D. (6, 4, 5, 2, 1, 3)

selected by
0 votes
0 votes
the simple stack operation will be given by :

starting from the vertex 4

stack:(3,1,2,5,4,6) or  (1,2,3,5,4,6)

after popping from the stack : 6 4 5 2 1 3   or 6 4 5 3 2 1

option (D) is correct

Note: In topological sorting,a vertex having maximum incoming edges always at the last position
Answer:

Related questions

0 votes
0 votes
1 answer
1
Bikram asked May 26, 2017
487 views
The cost of optimal binary search tree for the identifier set $(a1, a2, a3) =$ (do, if, while) with $p(1) = 0.3, \ p(2) = 0.2, $ $p(3) = 0.15, q (0) = 0.05, q(1) = 0.15...
2 votes
2 votes
2 answers
3
Bikram asked May 26, 2017
371 views
Assume Dijkstra's Algorithm is used to find the shortest paths from node G in the above graph. The total number of edges which are not included in any of the shortest pat...
1 votes
1 votes
2 answers
4
Bikram asked May 26, 2017
486 views
The total number of LCS (Longest Common Subsequences) of $P = abcd123$ and $Q= badc321$ that can be formed are ______.