Created
September 16, 2017 05:10
-
-
Save bvsbrk/27385946824723b8e48c9c75e48fc7ef to your computer and use it in GitHub Desktop.
Description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vertex: | |
def __init__(self, id): | |
self.connections = {} | |
self.id = id | |
def addNeighbor(self, id, weight): | |
if id not in self.connections: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-- > Vertex is a node in Graph
Each vertex will have an id and a dictionary (actually it is adjacency list).
The dictionary is implemented as follows :
The key in the dictionary is the node which is connected to this vertex and its value is the weight of the edge that connects this vertex to this node
Eg : a is connected to b and the weight of edge is 1 and a is connected to c and edge weight is 2
The adjacency list looks like this
a ==> {
"b" : 1,
"c" : 2
}