Given a set of vertices, how do you create a strongly connected directed graph with an almost minimal number of edges?

I am trying to test on my graph class dijkstras algorithm. To do this, I create a graph with several thousand vertices, and then create a graph connected by randomly adding thousands of edges until the graph is connected. Then I can search between any two random vertices again and again and make sure there is a path between them. The problem is that I often end up with an almost dense graph, which, since I use the adjacency list view, causes my search algorithm to be very slow.

Question : Given the set of vertices V, how do you create a strongly connected oriented graph that has significantly fewer edges than a dense graph over the same vertices?

I thought just to do the following:

vertex 1 <--> vertex 2, vertex 2 <--> vertex 3, ..., vertex n-1 <--> vertex n

And then randomly adding as n / 10 edges across the graph, but this doesn't seem like the best way to pick random graph structures to test my search algorithms.

+4
source share
2 answers

, ( |V| ) , , .

, .

EDIT: , , . .

+1

, , , , :

  • E () . .
  • , , , . "" , . , , ( ). , .
  • , , , . , DFS, node , , , . , DFS .

, , - , , , , . , , .

EDIT:

  • , . .
+1

Source: https://habr.com/ru/post/1570530/


All Articles