WHILE SOLVING PROBLEM OF TOPOLOGICAL SORTING WE CAN USE SOME GENERAL APPROACH TO SOLVE PROBLEM (THINK SOLUTION OF PROBLEM).
1->
TOPOLOGICAL SORT IS IMPLEMENTED IN 2 WAYS (a) STACK (b) QUEUE.
(a) USING STACK
WITH HELP OF STACK WE CAN GET ORDER IN TOP TO DOWN MANNER , IN SOME PROBLEM WE CAN USE THIS PROPERTY..
using this method
if topo sort of a graph is 4,5,2,1,3
than it will first generate 4 , then 5, .............
(B) USING QUEUE
WITH HELP OF QUEUE WE CAN GET ORDER IN BOTTOM UP ORDER. IN SOME PROBLEM WE CAN USE THIS PROPERTY..
using this method
if topo sort of a graph is 4,5,2,1,3
than it will first generate 3 , then 1, .............
2->
SUPPOSE A GRAPH IS GIVEN IN A PROBLEM RELATED TO TOPO SORT ,SINCE THE GRAPH WILL BE DIRECTED (TOPO GRAPH ARE DIRECTED ALWAYS ) DIRECTED , SOME TIME WE CAN REVERSE DIRECTION OF THE EDGE AND THINK THE SOLUTION..
3->
1->
TOPOLOGICAL SORT IS IMPLEMENTED IN 2 WAYS (a) STACK (b) QUEUE.
(a) USING STACK
WITH HELP OF STACK WE CAN GET ORDER IN TOP TO DOWN MANNER , IN SOME PROBLEM WE CAN USE THIS PROPERTY..
using this method
if topo sort of a graph is 4,5,2,1,3
than it will first generate 4 , then 5, .............
(B) USING QUEUE
WITH HELP OF QUEUE WE CAN GET ORDER IN BOTTOM UP ORDER. IN SOME PROBLEM WE CAN USE THIS PROPERTY..
using this method
if topo sort of a graph is 4,5,2,1,3
than it will first generate 3 , then 1, .............
2->
SUPPOSE A GRAPH IS GIVEN IN A PROBLEM RELATED TO TOPO SORT ,SINCE THE GRAPH WILL BE DIRECTED (TOPO GRAPH ARE DIRECTED ALWAYS ) DIRECTED , SOME TIME WE CAN REVERSE DIRECTION OF THE EDGE AND THINK THE SOLUTION..
3->