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

Method minimum_distance

graphs/dijkstra_alternate.py:27–47  ·  view source on GitHub ↗

A utility function to find the vertex with minimum distance value, from the set of vertices not yet included in shortest path tree. >>> Graph(3).minimum_distance([1, 2, 3], [False, False, True]) 0

(
        self, distances_from_source: list[int], visited: list[bool]
    )

Source from the content-addressed store, hash-verified

25 print(vertex, "\t\t", distances_from_source[vertex])
26
27 def minimum_distance(
28 self, distances_from_source: list[int], visited: list[bool]
29 ) -> int:
30 """
31 A utility function to find the vertex with minimum distance value, from the set
32 of vertices not yet included in shortest path tree.
33
34 >>> Graph(3).minimum_distance([1, 2, 3], [False, False, True])
35 0
36 """
37
38 # Initialize minimum distance for next node
39 minimum = 1e7
40 min_index = 0
41
42 # Search not nearest vertex not in the shortest path tree
43 for vertex in range(self.vertices):
44 if distances_from_source[vertex] < minimum and visited[vertex] is False:
45 minimum = distances_from_source[vertex]
46 min_index = vertex
47 return min_index
48
49 def dijkstra(self, source: int) -> None:
50 """

Callers 1

dijkstraMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected