in Algorithms
1,335 views
0 votes
0 votes

If we apply  Topological and DFS traversal.

Is there any intersection of ordering? Please explain. 

in Algorithms
1.3k views

1 Answer

2 votes
2 votes
Best answer
in this particular graph, there is no intersection of topological sort an DFS order.

How?

we all know that if the graph contains a→b and c→b present, in topological order b should be visited after a and c.

in the above graph 1 → 2 and 1 → 4 present, these two individual chains met at 7, i mean 7 should be visited after 2 and 4 visited in any topological sort

coming to DFS starts with 1 ( due to checking for intersection ) either go with 2 or 4 ( either if 2 completely visits then 4 visited or if 4 completely visits then 2 visited )

     i) go with next node 2, 2 → 7, that implies 7 should be visited before going back to 1 ==> 4 should be doesn't visited before 7 visited ===> NO intersection with Topological sort

     ii) go with next node 4, 4 → 7, that implies 7 should be visited before going back to 1 ==> 2 should be doesn't visited before 7 visited ===> NO intersection with Topological sort
selected by

15 Comments

Thanks @shaik brother
0
0
@Rishav

if u want intersection between DFS traversal and topological sort

then here every node is in intersection
0
0

Yes ma'am but in question they are asking about ordering.

Is there any intersection of ordering? 

0
0
here topological order is 1-2-3-4-5-6-7-8-9

dfs order is 1-2-3-4-5-6-7-8-9

intersection of both is 1-2-3-4-5-6-7-8-9
0
0
Yes correct, but i think this can't be possible with this graph that both have same ordering
0
0
here topological order is 1-2-3-4-5-6-7-8-9 is possible BUT

dfs order is 1-2-3-4-5-6-7-8-9 can't be possible.

Correct me ?
0
0
why?
0
0
Bcz  after 1->2->3 we can't go to 4  we have to go to 7, so 1->2->3->4 is not possible.
0
0
yes

DFS will be 1-2-3-7-8-4-5-9-6 which is not possible in topological sort
2
2
Ma'am how many total topological ordering possible on this graph?
I tried but it's very complex for big graphs. Is there any shortcut?
0
0
will be 16

After 1 there will be two path 2 and 4

fro 4 there will be again 2 path 5 and 6

and also 7. cannot occur before 2 and 8 cannot occur before 5
0
0
I didn't get, how you got 16. Please explain
0
0

I got this diagram

I got this diagram

if I remove 1, will get two option to choose 2 or 4.........i

Now remove 4 we get again two option 6 or 5..............ii

Now remove 6 , got two option 7 or 3..........................iii

Now remove 7 , we got last 2. option 8 or 9.................iv

thus $2^{4}=16$

0
0

@Rishav Kumar Singh

after 1->2->3 we can't go to 4  we have to go to 7, so 1->2->3->4 is not possible.WHY??

0
0

@Shaik Masthan

Topological sort mainly use DFS, not BFS. right??

0
0

Related questions

2 votes
2 votes
0 answers
1
h4kr asked in Algorithms Jan 10, 2023
349 views
h4kr asked in Algorithms Jan 10, 2023
by h4kr
349 views
1 vote
1 vote
1 answer
3