Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: c40c816263
...
compare: d0936bd77a
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 52 additions and 2 deletions.
  1. +1 −1  kruskalClass.py
  2. +1 −1  kruskalFunction.py
  3. +50 −0 primsFunction.py
View
2  kruskalClass.py
@@ -28,7 +28,7 @@ def find (self, u):
i = 0
for c in self.C:
if (u in c): return (c,i)
- i = i + 1
+ i += 1
def merge (self, ucomp, vcomp):
self.C = [ucomp[0] + vcomp[0]] + [i for j, i in enumerate(self.C) if j not in [ucomp[1], vcomp[1]]]
View
2  kruskalFunction.py
@@ -7,7 +7,7 @@ def find (u, C):
i = 0
for c in C:
if (u in c): return (c,i)
- i = i + 1
+ i += 1
def merge (C, ucomp, vcomp):
return [ucomp[0] + vcomp[0]] + [i for j, i in enumerate(C) if j not in [ucomp[1], vcomp[1]]]
View
50 primsFunction.py
@@ -0,0 +1,50 @@
+def Prim (Adj):
+ T = []
+ n = len(Adj)
+ Nearest = []
+ MinDist = []
+
+ for i in range(0,n):
+ Nearest.append(0)
+ MinDist.append(0)
+
+ for i in range(1, n):
+ Nearest[i] = 0
+ MinDist[i] = Adj[i][0]
+
+ for i in range(0, n-1):
+ min = None
+ for j in range(1, n):
+ if ((min and MinDist[j] and 0 <= MinDist[j] < min) or (not min and 0 <= MinDist[j])):
+ min = MinDist[j]
+ k = j
+
+ T.append((k, Nearest[k]))
+ print T
+
+ MinDist[k] = -1
+ MinDist[Nearest[k]] = -1
+
+ for j in range(1, n):
+ if ((MinDist[j] and Adj[k][j] and Adj[k][j] < MinDist[j]) or not MinDist[j] ):
+ MinDist[j] = Adj[k][j]
+ MinDist[k] = Adj[j][k]
+
+ Nearest[j] = k
+ Nearest[k] = j
+
+ return T
+
+# My experiment
+
+# My experiment
+
+Adj = [[None, 1, None, 4, None, None, None],
+[1, None, 2, 6, 4, None, None],
+[None, 2, None, None, 5, 6, None],
+[4, 6, None, None, 3, None, 4],
+[None, 4, 5, 3, None, 8, 7],
+[None, None, 6, None, 8, None, 3],
+[None, None, None, 4, 7, 3, None]]
+
+Prim(Adj)

No commit comments for this range

Something went wrong with that request. Please try again.