Skip to content

Commit

Permalink
#9943 : Adding coverage test for basic_graphs.py (#12354)
Browse files Browse the repository at this point in the history
* #9943 : Adding coverage test for basic_graphs.py

* #9943 : Adding coverage test for basic_graphs.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Solve problem of line too long

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Scarfinos and pre-commit-ci[bot] authored Dec 30, 2024
1 parent 7742536 commit 75c5c41
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions graphs/basic_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ def initialize_weighted_undirected_graph(


def dfs(g, s):
"""
>>> dfs({1: [2, 3], 2: [4, 5], 3: [], 4: [], 5: []}, 1)
1
2
4
5
3
"""
vis, _s = {s}, [s]
print(s)
while _s:
Expand Down Expand Up @@ -104,6 +112,17 @@ def dfs(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])
print(s)
while q:
Expand All @@ -128,6 +147,19 @@ def bfs(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}
while True:
if len(known) == len(g) - 1:
Expand Down

0 comments on commit 75c5c41

Please sign in to comment.