We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3136833 commit eeeae84Copy full SHA for eeeae84
graphs/basic_graphs.py
@@ -77,14 +77,6 @@ def initialize_weighted_undirected_graph(
77
78
79
def dfs(g, s):
80
- """
81
- >>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1)
82
- 1
83
- 2
84
- 4
85
- 5
86
- 3
87
88
vis, _s = {s}, [s]
89
print(s)
90
while _s:
@@ -112,17 +104,6 @@ def dfs(g, s):
112
104
113
105
114
106
def bfs(g, s):
115
116
- >>> bfs({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [], 5: [8], 6: [], 7: [], 8: []}, 1)
117
118
119
120
121
122
- 6
123
- 7
124
- 8
125
126
107
vis, q = {s}, deque([s])
127
108
128
109
while q:
@@ -147,19 +128,6 @@ def bfs(g, s):
147
148
129
149
130
def dijk(g, s):
150
151
- dijk({1: [(2, 7), (3, 9), (6, 14)],
152
- 2: [(1, 7), (3, 10), (4, 15)],
153
- 3: [(1, 9), (2, 10), (4, 11), (6, 2)],
154
- 4: [(2, 15), (3, 11), (5, 6)],
155
- 5: [(4, 6), (6, 9)],
156
- 6: [(1, 14), (3, 2), (5, 9)]}, 1)
157
158
- 9
159
- 11
160
- 20
161
162
163
131
dist, known, path = {s: 0}, set(), {s: 0}
164
132
while True:
165
133
if len(known) == len(g) - 1:
0 commit comments