Generating Random Directed Unweighted Graphs
- Since this is a graph, the test data generation plan doesn't guarantee that a cycle gets formed or not.
- The number of edges - NUMEDGE is greater than zero and less than NUM*(NUM-1)/2, where NUM = Number of Vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUMEDGE lines are of the form (a b) where a is connected to b and the edge is directed from a to b (a->b)
- Each of the NUMEDGE lines will have distinct edges, for e.g – if (1, 2) is there in one of the NUMEDGE lines then it is guaranteed, that (1, 2) will not be there in the remaining NUMEDGE-1 lines as this is a directed graph.
Example
Generating Random Directed Weighted Graphs
- Since this is a graph, the test data generation plan doesn't guarantee that a cycle gets formed or not.
- The number of edges - NUMEDGE is greater than zero and less than NUM*(NUM-1)/2, where NUM = Number of Vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUMEDGE lines are of the form (a b wt) where a is connected to b and the edge is directed from a to b (a->b) and the edge has a weight of wt
- Each of the NUMEDGE lines will have distinct edges, for e.g – if (1, 2) is there in one of the NUMEDGE lines then it is guaranteed, that (1, 2) will not be there in the remaining NUMEDGE-1 lines as this is a directed graph.
Example:
Output...63
17 14 92
18 1 62
18 3 161
18 13 182
18 18 83
19 1 20
19 15 96
19 17 196
3 1
3 1 88
17 104
1 1 109
1 5 104
1 7 72
1 10 116
2 1 184
2 4 115
2 5 180
2 7 94
2 8 139
2 9 113
2 11 130
2 14 119
2 15 121
2 16 24
3 3 88
3 5 55
3 6 137
3 12 158
3 13 16
3 15 66
4 5 196
4 11 165
4 12 197
4 14 186
4 15 97
5 1 59
5 3 107
5 7 46
5 9 104
5 15 115
5 17 109
6 1 164
6 4 171
6 6 180
6 8 31
6 11 154
6 14 46
6 15 162
6 17 199
7 9 185
7 11 75
7 15 80
7 17 103
8 1 147
8 2 56
8 7 142
8 9 2
8 14 192
8 15 100
8 16 169
8 17 10
9 2 95
9 7 133
9 8 6
9 12 33
9 17 29
10 3 65
10 6 91
10 7 26
10 8 120
10 9 5
10 14 135
10 17 35
11 8 175
11 9 66
11 12 18
11 15 80
12 2 112
12 3 179
12 4 30
12 5 96
12 9 5
12 11 110
12 16 150
13 1 152
13 5 165
13 9 92
13 14 153
13 15 108
13 16 191
14 1 73
14 2 117
14 5 37
14 6 5
14 7 123
14 11 69
14 13 185
14 17 139
15 1 111
15 3 10
15 6 10
15 7 116
15 9 144
15 10 196
15 14 42
15 16 162
16 4 13
16 5 74
16 6 73
16 7 144
16 10 103
16 17 120
17 12 148
17 13 12
9 3
2 2 74
5 5 111
9 2 15
Generating Random Undirected Unweighted Graphs
- Since this is a graph, the test data generation plan doesn't guarantee that a cycle gets formed or not.
- The number of edges - NUMEDGE is greater than zero and less than NUM*(NUM-1)/2, where NUM = Number of Vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUMEDGE lines are of the form (a b) where a is connected to b
- Each of the NUMEDGE lines will have distinct edges, for e.g – if (1, 2) is there in one of the NUMEDGE lines then it is guaranteed, that (1, 2) and (2, 1) both will not be there in the remaining NUMEDGE-1 lines as this is an undirected graph.
Generating Random Undirected Weighted Graphs
- Since this is a graph, the test data generation plan doesn't guarantee that a cycle gets formed or not.
- The number of edges - NUMEDGE is greater than zero and less than NUM*(NUM-1)/2, where NUM = Number of Vertices
- For each RUN we first print the number of vertices - NUM first in a new separate line and the next NUMEDGE lines are of the form (a b wt) where a is connected to b and the edge has a weight of wt
- Each of the NUMEDGE lines will have distinct edges, for e.g – if (1, 2) is there in one of the NUMEDGE lines then it is guaranteed, that (1, 2) and (2, 1) both will not be there in the remaining NUMEDGE-1 lines as this is an undirected graph.
Time Complexity :O(RUN*(MAX_EDGES+MAX_VERTICES*log(MAX_VERTICES))), where RUN is the number of test cases generated, MAX_EDGES is the maximum number of edges, and MAX_VERTICES is the maximum number of vertices. This is because the outer loop runs for 'RUN' times, and the inner loop runs for 'MAX_EDGES' times. The set container used in the code has a time complexity of O(log(MAX_VERTICES)) for insert, find, and clear operations.
Space complexity : O(MAX_VERTICES*RUN), as the container set is used to store the edges and its size grows as the number of vertices in the graph increases, and this is multiplied by the number of test cases generated.