-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKruskal_test.txt
More file actions
257 lines (208 loc) · 6.63 KB
/
Kruskal_test.txt
File metadata and controls
257 lines (208 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
enter the number of nodes in the graph
10
enter the Node no:1's key
a
enter the Node no:2's key
b
enter the Node no:3's key
c
enter the Node no:4's key
d
enter the Node no:5's key
e
enter the Node no:6's key
f
enter the Node no:7's key
g
enter the Node no:8's key
h
enter the Node no:9's key
i
enter the Node no:10's key
j
enter the number of edges in the graph
21
For the Edge no:1
of the 2 nodes involved in this edge
enter the first Node's key
a
enter the second Node's key
b
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:2
of the 2 nodes involved in this edge
enter the first Node's key
a
enter the second Node's key
c
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:3
of the 2 nodes involved in this edge
enter the first Node's key
a
enter the second Node's key
f
enter the cost (or weight) of this edge (or arc) - an integer
8
For the Edge no:4
of the 2 nodes involved in this edge
enter the first Node's key
a
enter the second Node's key
j
enter the cost (or weight) of this edge (or arc) - an integer
18
For the Edge no:5
of the 2 nodes involved in this edge
enter the first Node's key
b
enter the second Node's key
c
enter the cost (or weight) of this edge (or arc) - an integer
3
For the Edge no:6
of the 2 nodes involved in this edge
enter the first Node's key
b
enter the second Node's key
e
enter the cost (or weight) of this edge (or arc) - an integer
6
For the Edge no:7
of the 2 nodes involved in this edge
enter the first Node's key
c
enter the second Node's key
e
enter the cost (or weight) of this edge (or arc) - an integer
4
For the Edge no:8
of the 2 nodes involved in this edge
enter the first Node's key
c
enter the second Node's key
d
enter the cost (or weight) of this edge (or arc) - an integer
2
For the Edge no:9
of the 2 nodes involved in this edge
enter the first Node's key
c
enter the second Node's key
f
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:10
of the 2 nodes involved in this edge
enter the first Node's key
d
enter the second Node's key
e
enter the cost (or weight) of this edge (or arc) - an integer
2
For the Edge no:11
of the 2 nodes involved in this edge
enter the first Node's key
d
enter the second Node's key
f
enter the cost (or weight) of this edge (or arc) - an integer
8
For the Edge no:12
of the 2 nodes involved in this edge
enter the first Node's key
d
enter the second Node's key
g
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:13
of the 2 nodes involved in this edge
enter the first Node's key
e
enter the second Node's key
g
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:14
of the 2 nodes involved in this edge
enter the first Node's key
f
enter the second Node's key
g
enter the cost (or weight) of this edge (or arc) - an integer
7
For the Edge no:15
of the 2 nodes involved in this edge
enter the first Node's key
f
enter the second Node's key
i
enter the cost (or weight) of this edge (or arc) - an integer
9
For the Edge no:16
of the 2 nodes involved in this edge
enter the first Node's key
f
enter the second Node's key
j
enter the cost (or weight) of this edge (or arc) - an integer
10
For the Edge no:17
of the 2 nodes involved in this edge
enter the first Node's key
g
enter the second Node's key
i
enter the cost (or weight) of this edge (or arc) - an integer
5
For the Edge no:18
of the 2 nodes involved in this edge
enter the first Node's key
g
enter the second Node's key
h
enter the cost (or weight) of this edge (or arc) - an integer
4
For the Edge no:19
of the 2 nodes involved in this edge
enter the first Node's key
h
enter the second Node's key
i
enter the cost (or weight) of this edge (or arc) - an integer
1
For the Edge no:20
of the 2 nodes involved in this edge
enter the first Node's key
h
enter the second Node's key
j
enter the cost (or weight) of this edge (or arc) - an integer
4
For the Edge no:21
of the 2 nodes involved in this edge
enter the first Node's key
i
enter the second Node's key
j
enter the cost (or weight) of this edge (or arc) - an integer
3
enter the maximum weight possible for any of edges in the graph
20
The edges with thier unsorted weights are
{('g', 'e'): [9], ('b', 'c'): [3], ('e', 'd'): [2], ('h', 'i'): [1], ('d', 'e'): [2], ('i', 'h'): [1], ('f', 'd'): [8], ('c', 'b'): [3], ('e', 'c'): [4], ('a', 'b'): [9], ('g', 'd'): [9], ('c', 'f'): [9], ('f', 'a'): [8], ('e', 'g'): [9], ('d', 'f'): [8], ('d', 'g'): [9], ('c', 'a'): [9], ('h', 'j'): [4], ('e', 'b'): [6], ('i', 'g'): [5], ('d', 'c'): [2], ('c', 'e'): [4], ('g', 'h'): [4], ('b', 'a'): [9], ('i', 'j'): [3], ('j', 'h'): [4], ('a', 'f'): [8], ('j', 'a'): [18], ('i', 'f'): [9], ('f', 'j'): [10], ('c', 'd'): [2], ('h', 'g'): [4], ('f', 'c'): [9], ('g', 'i'): [5], ('j', 'f'): [10], ('g', 'f'): [7], ('j', 'i'): [3], ('b', 'e'): [6], ('f', 'g'): [7], ('a', 'c'): [9], ('a', 'j'): [18], ('f', 'i'): [9]}
After sorting
[(('h', 'i'), [1]), (('i', 'h'), [1]), (('e', 'd'), [2]), (('d', 'e'), [2]), (('d', 'c'), [2]), (('c', 'd'), [2]), (('b', 'c'), [3]), (('c', 'b'), [3]), (('i', 'j'), [3]), (('j', 'i'), [3]), (('e', 'c'), [4]), (('h', 'j'), [4]), (('c', 'e'), [4]), (('g', 'h'), [4]), (('j', 'h'), [4]), (('h', 'g'), [4]), (('i', 'g'), [5]), (('g', 'i'), [5]), (('e', 'b'), [6]), (('b', 'e'), [6]), (('g', 'f'), [7]), (('f', 'g'), [7]), (('f', 'd'), [8]), (('f', 'a'), [8]), (('d', 'f'), [8]), (('a', 'f'), [8]), (('g', 'e'), [9]), (('a', 'b'), [9]), (('g', 'd'), [9]), (('c', 'f'), [9]), (('e', 'g'), [9]), (('d', 'g'), [9]), (('c', 'a'), [9]), (('b', 'a'), [9]), (('i', 'f'), [9]), (('f', 'c'), [9]), (('a', 'c'), [9]), (('f', 'i'), [9]), (('f', 'j'), [10]), (('j', 'f'), [10]), (('j', 'a'), [18]), (('a', 'j'), [18])]
In the graph with these vertex's
['a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'j']
With these edges between the vertexes given above, we obtain a Minimal Spanning Tree
{('b', 'c'): [3], ('g', 'f'): [7], ('e', 'd'): [2], ('h', 'i'): [1], ('g', 'h'): [4], ('f', 'd'): [8], ('f', 'a'): [8], ('d', 'c'): [2], ('i', 'j'): [3]}
Please note this is a dictionary with key as the weight of the edge and value as the key's of the two vertex's involved in this edge
>>>