MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

graphs/dijkstra_algorithm.py:214–233  ·  view source on GitHub ↗

Graph class constructor Examples: >>> graph_test = Graph(1) >>> graph_test.num_nodes 1 >>> graph_test.dist [0] >>> graph_test.par [-1] >>> graph_test.adjList {}

(self, num)

Source from the content-addressed store, hash-verified

212
213class Graph:
214 def __init__(self, num):
215 """
216 Graph class constructor
217
218 Examples:
219 >>> graph_test = Graph(1)
220 >>> graph_test.num_nodes
221 1
222 >>> graph_test.dist
223 [0]
224 >>> graph_test.par
225 [-1]
226 >>> graph_test.adjList
227 {}
228 """
229 self.adjList = {} # To store graph: u -> (v,w)
230 self.num_nodes = num # Number of nodes in graph
231 # To store the distance from source vertex
232 self.dist = [0] * self.num_nodes
233 self.par = [-1] * self.num_nodes # To store the path
234
235 def add_edge(self, u, v, w):
236 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected