问题
Let's say we have a fully connected digraph G
with N
vertices and M
edges.
How many edges does the graph have? Is it M = N^2
?
If we take one vertex and start visiting its neighbors in a 'depth-first search' manner and avoiding loops, how many non-cyclic simple paths will we get?
For example, if we start from vertex 1 in a graph of 4 vertices, here are the paths:
- 1
- 1,2
- 1,3
- 1,4
- 1,2,3
- 1,2,4
- 1,3,2
- 1,3,4
- 1,4,2
- 1,4,3
Is it N!
or more for a graph with N
vertices? I could not find a way to generalize this and to derive a usable formula.
回答1:
If your graph is full, there are n!
simple paths for each vertex, so total of n*n!
simple paths in the graph.
let a starting vertex be v_1
.
There are |V|
possibilities what to do next: move to one of each V\{v_1}
, or stop.
next you have |V|-1
possibilities: move to one of each V\{v_1,v_2}
[where v_2 is the node chosen as second] or stop.
... [do induction to formally prove it here]
after you have a path of n
nodes, there is one only possibility: stop.
giving you total of n*(n-1)*...*1 = n!
possible simple paths for each vertex, and n*n!
total possible simple paths in the graph
来源:https://stackoverflow.com/questions/8457805/what-is-the-number-of-all-possible-non-cyclic-simple-paths-in-a-fully-connected