@@ -6,16 +6,17 @@ def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
6
6
Check if a graph is bipartite using depth-first search (DFS).
7
7
8
8
Args:
9
- graph: Adjacency list representing the graph.
9
+ ` graph` : Adjacency list representing the graph.
10
10
11
11
Returns:
12
- True if bipartite, False otherwise.
12
+ `` True`` if bipartite, `` False`` otherwise.
13
13
14
14
Checks if the graph can be divided into two sets of vertices, such that no two
15
15
vertices within the same set are connected by an edge.
16
16
17
17
Examples:
18
- # FIXME: This test should pass.
18
+
19
+ >>> # FIXME: This test should pass.
19
20
>>> is_bipartite_dfs(defaultdict(list, {0: [1, 2], 1: [0, 3], 2: [0, 4]}))
20
21
Traceback (most recent call last):
21
22
...
@@ -37,7 +38,7 @@ def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
37
38
...
38
39
KeyError: 0
39
40
40
- # FIXME: This test should fails with KeyError: 4.
41
+ >>> # FIXME: This test should fails with KeyError: 4.
41
42
>>> is_bipartite_dfs({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 9: [0]})
42
43
False
43
44
>>> is_bipartite_dfs({0: [-1, 3], 1: [0, -2]})
@@ -51,7 +52,8 @@ def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
51
52
...
52
53
KeyError: 0
53
54
54
- # FIXME: This test should fails with TypeError: list indices must be integers or...
55
+ >>> # FIXME: This test should fails with
56
+ >>> # TypeError: list indices must be integers or...
55
57
>>> is_bipartite_dfs({0: [1.0, 3.0], 1.0: [0, 2.0], 2.0: [1.0, 3.0], 3.0: [0, 2.0]})
56
58
True
57
59
>>> is_bipartite_dfs({"a": [1, 3], "b": [0, 2], "c": [1, 3], "d": [0, 2]})
@@ -95,16 +97,17 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
95
97
Check if a graph is bipartite using a breadth-first search (BFS).
96
98
97
99
Args:
98
- graph: Adjacency list representing the graph.
100
+ ` graph` : Adjacency list representing the graph.
99
101
100
102
Returns:
101
- True if bipartite, False otherwise.
103
+ `` True`` if bipartite, `` False`` otherwise.
102
104
103
105
Check if the graph can be divided into two sets of vertices, such that no two
104
106
vertices within the same set are connected by an edge.
105
107
106
108
Examples:
107
- # FIXME: This test should pass.
109
+
110
+ >>> # FIXME: This test should pass.
108
111
>>> is_bipartite_bfs(defaultdict(list, {0: [1, 2], 1: [0, 3], 2: [0, 4]}))
109
112
Traceback (most recent call last):
110
113
...
@@ -126,7 +129,7 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
126
129
...
127
130
KeyError: 0
128
131
129
- # FIXME: This test should fails with KeyError: 4.
132
+ >>> # FIXME: This test should fails with KeyError: 4.
130
133
>>> is_bipartite_bfs({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 9: [0]})
131
134
False
132
135
>>> is_bipartite_bfs({0: [-1, 3], 1: [0, -2]})
@@ -140,7 +143,8 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
140
143
...
141
144
KeyError: 0
142
145
143
- # FIXME: This test should fails with TypeError: list indices must be integers or...
146
+ >>> # FIXME: This test should fails with
147
+ >>> # TypeError: list indices must be integers or...
144
148
>>> is_bipartite_bfs({0: [1.0, 3.0], 1.0: [0, 2.0], 2.0: [1.0, 3.0], 3.0: [0, 2.0]})
145
149
True
146
150
>>> is_bipartite_bfs({"a": [1, 3], "b": [0, 2], "c": [1, 3], "d": [0, 2]})
0 commit comments