Skip to content

Commit b93d675

Browse files
author
BuildTools
committed
added algorithms
1 parent 8215ebb commit b93d675

File tree

11 files changed

+654
-0
lines changed

11 files changed

+654
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
# Algorithms
2+
INCLUDES
3+
4+
MergeSort
5+
InsertionSort
6+
QuickSort
7+
8+
Graph Algorithms:
9+
Kruskal's Algorithm (undirected)
10+
Prim's Algorithm (undirected)
11+
Dijkstra's Algorithm (undirected)
Binary file not shown.

graphParseAndPlotUndirected/graph.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''
2+
Created on Nov 8, 2014
3+
4+
@author: Gary
5+
'''
6+
7+
class graph:
8+
def __init__(self):
9+
self.vertexNameArray = [] # vertex names in an array
10+
self.vertexIndexMap = {} # vertex names to index dictionary
11+
self.vertexPositionArray = [] # x,y pair position array
12+
self.edgeArray = [] # array of (vertex index pair, weight)
13+
14+
def addVertex(self, name, x, y):
15+
self.vertexIndexMap[name] = self.vCount()
16+
self.vertexNameArray.append(name)
17+
self.vertexPositionArray.append((x,y))
18+
19+
def addEdge(self, vName1, vName2, weight):
20+
self.edgeArray.append((self.vertexIndexMap[vName1],self.vertexIndexMap[vName2],weight))
21+
22+
def newEdgeWeight(self, i_edge, new_weight):
23+
self.edgeArray[i_edge][2] = new_weight
24+
25+
def vCount(self): return len(self.vertexNameArray)
26+
27+
def eCount(self): return len(self.edgeArray)
28+
29+
# Access functions for vertex information
30+
def vX( self, i): return self.vertexPositionArray[i][0]
31+
def vY( self, i): return self.vertexPositionArray[i][1]
32+
def vName(self, i): return self.vertexNameArray[i]
33+
def vIndx(self, v): return self.vertexIndexMap[v]
34+
35+
# Access functions for edge information
36+
def eV0X( self, i): return self.vertexPositionArray[self.edgeArray[i][0]][0]
37+
def eV0Y( self, i): return self.vertexPositionArray[self.edgeArray[i][0]][1]
38+
def eV1X( self, i): return self.vertexPositionArray[self.edgeArray[i][1]][0]
39+
def eV1Y( self, i): return self.vertexPositionArray[self.edgeArray[i][1]][1]
40+
def eWght(self, i): return self.edgeArray[i][2]

graphParseAndPlotUndirected/graph.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a 20 30
2+
b 200 40
3+
c 30 350
4+
----------
5+
a b 3
6+
b c 4
7+
a c 5
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
a 20 30
2+
b 200 40
3+
c 30 350
4+
d 350 380
5+
e 100 300
6+
f 340 25
7+
g 200 250
8+
----------
9+
a b 3
10+
b c 4
11+
a c 5
12+
a d 4
13+
b d 2
14+
c d 1
15+
e a 2
16+
a f 5
17+
e c 3
18+
e d 3
19+
d f 2
20+
e g 1
21+
b g 2
22+
d g 3
23+
b f 2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
a 20 30
2+
b 100 40
3+
c 30 250
4+
d 60 130
5+
e 150 90
6+
f 240 60
7+
g 120 200
8+
h 200 160
9+
i 260 100
10+
j 360 400
11+
l 180 350
12+
m 280 300
13+
n 80 350
14+
o 350 40
15+
----------
16+
a b 3
17+
a c 2
18+
a d 5
19+
b c 4
20+
b d 1
21+
b g 2
22+
c d 7
23+
c g 5
24+
e f 4
25+
e g 3
26+
e h 2
27+
f h 3
28+
f i 4
29+
g l 1
30+
g n 1
31+
h i 1
32+
h m 3
33+
i m 2
34+
i o 2
35+
j l 7
36+
j m 3
37+
j o 4
38+
l m 5
39+
l n 6
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
a 10 100
2+
b 100 200
3+
c 200 200
4+
d 300 200
5+
e 390 100
6+
f 300 10
7+
g 200 10
8+
h 100 10
9+
i 150 100
10+
----------
11+
a b 4
12+
b c 8
13+
b h 11
14+
a h 8
15+
h i 7
16+
h g 1
17+
i c 2
18+
i g 6
19+
c f 4
20+
g f 2
21+
c d 7
22+
d e 9
23+
d f 14
24+
e f 10

0 commit comments

Comments
 (0)