mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
fix more than one file
This commit is contained in:
parent
3136833d4a
commit
eeeae84631
|
@ -77,14 +77,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
|
|
||||||
def dfs(g, s):
|
def dfs(g, s):
|
||||||
"""
|
|
||||||
>>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1)
|
|
||||||
1
|
|
||||||
2
|
|
||||||
4
|
|
||||||
5
|
|
||||||
3
|
|
||||||
"""
|
|
||||||
vis, _s = {s}, [s]
|
vis, _s = {s}, [s]
|
||||||
print(s)
|
print(s)
|
||||||
while _s:
|
while _s:
|
||||||
|
@ -112,17 +104,6 @@ def dfs(g, s):
|
||||||
|
|
||||||
|
|
||||||
def bfs(g, s):
|
def bfs(g, s):
|
||||||
"""
|
|
||||||
>>> bfs({1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [], 5: [8], 6: [], 7: [], 8: []}, 1)
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
"""
|
|
||||||
vis, q = {s}, deque([s])
|
vis, q = {s}, deque([s])
|
||||||
print(s)
|
print(s)
|
||||||
while q:
|
while q:
|
||||||
|
@ -147,19 +128,6 @@ def bfs(g, s):
|
||||||
|
|
||||||
|
|
||||||
def dijk(g, s):
|
def dijk(g, s):
|
||||||
"""
|
|
||||||
dijk({1: [(2, 7), (3, 9), (6, 14)],
|
|
||||||
2: [(1, 7), (3, 10), (4, 15)],
|
|
||||||
3: [(1, 9), (2, 10), (4, 11), (6, 2)],
|
|
||||||
4: [(2, 15), (3, 11), (5, 6)],
|
|
||||||
5: [(4, 6), (6, 9)],
|
|
||||||
6: [(1, 14), (3, 2), (5, 9)]}, 1)
|
|
||||||
7
|
|
||||||
9
|
|
||||||
11
|
|
||||||
20
|
|
||||||
20
|
|
||||||
"""
|
|
||||||
dist, known, path = {s: 0}, set(), {s: 0}
|
dist, known, path = {s: 0}, set(), {s: 0}
|
||||||
while True:
|
while True:
|
||||||
if len(known) == len(g) - 1:
|
if len(known) == len(g) - 1:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user