in Algorithms retagged by
1,640 views
3 votes
3 votes
Number of distinct BFS, DFS trees in a complete graph ?
in Algorithms retagged by
1.6k views

1 Answer

3 votes
3 votes
For DFS take a node, we have (n-1) possible tree edges, next we have all possible (n-2) tree edges,.......finally 1 possible tree edge. and we can choos any of n nodes as rooot node. hence no of distinct DFS trees= n*(n-1)*(n-2)*....*1=n!

 

For BFS tree if we take a node as root, we have to explore all its neighbors , so the number distinct of BFS trees =no of nodes we can choose as root ie. n .

3 Comments

Could you please clarify how this is wrong -

number of distinct dfs tree = C(C(n,2),n-1)?

The logic here is C(n,2) are total edges. Out of that select (n-1) edges.
0
0
@agoh,u cant use this formula as when u r choosing n-1 edges,it can also chosse those edges  which can form a cycle.
1
1
Thank you :)
0
0

Related questions