문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top