Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박권수
/
Algorithm_HW5
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2020-10-30 11:52:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0141d9db17991b2f6027ad4ae7ec404e1e4973a5
0141d9db
1 parent
5b81e805
feature1.0.1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
HW5_박권수_2015104173.py
HW5_박권수_2015104173.py
View file @
0141d9d
import
numpy
import
numpy
as
np
#Kruskal Algorithm
parent
=
dict
()
rank
=
dict
()
def
make_singleton_set
(
v
)
:
parent
[
v
]
=
v
rank
[
v
]
=
v
rank
[
v
]
=
1
def
find
(
v
)
:
if
(
parent
[
v
]
!=
v
)
:
...
...
@@ -31,4 +32,36 @@ def Kruskal(graph) :
edge_list
=
list
(
graph
[
'edges'
])
edge_list
.
sort
()
F
=
[]
\ No newline at end of file
F
=
set
()
index
=
0
while
len
(
F
)
<
n
-
1
:
e
=
edge_list
[
index
]
p
=
find
(
e
[
1
])
q
=
find
(
e
[
2
])
if
(
p
==
q
)
:
union
(
p
,
q
)
F
.
add
(
e
)
index
+=
1
return
F
graph
=
{
'vertices'
:
[
'A'
,
'B'
,
'C'
,
'D'
,
'E'
],
'edges'
:
set
([
(
1
,
'A'
,
'B'
),
(
3
,
'A'
,
'C'
),
(
3
,
'B'
,
'C'
),
(
6
,
'B'
,
'D'
),
(
4
,
'C'
,
'D'
),
(
2
,
'C'
,
'E'
),
(
5
,
'D'
,
'E'
),
])
}
for
i
in
range
(
0
,
5
)
:
make_singleton_set
(
i
)
mst
=
Kruskal
(
graph
)
print
(
mst
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment