Typing Course

Feedback
Settings
AccuracySpeedTimeErrors

100%

0WPM

0CPM

0s

0/0

"""⏎
Used to traverse trees, tree structures or graphs.⏎
Starts at a selected node (root) and explores the nearest⏎
neighbor branches before proceeding further.⏎
Time Complexity: O(E + V)⏎
E = Number of edges⏎
V = Number of vertices (nodes)⏎
Pseudocode: https://en.wikipedia.org/wiki/Breadth-first_search⏎
"""⏎
def bfs(graph, start):⏎
if start not in graph or graph[start] is None or graph[start] == []:⏎
return None⏎
visited, queue = set(), [start]⏎
while queue:⏎
vertex = queue.pop(0)⏎
if vertex not in visited:⏎
visited.add(vertex)⏎
queue.extend(graph[vertex] - visited)⏎
return visited⏎

This course is for Pro members.

Check this out! Our plans start at only 2.69 USD per month

Upgrade your account and SAVE 40% NOW!
Already have a Pro account? Sign in
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
backspace
tab
q
w
e
r
t
y
u
i
o
p
[{
]}
\|
capslock
a
s
d
f
g
h
j
k
l
;:
'"
enter
lshift
z
x
c
v
b
n
m
,<
.>
/?
rshift
fn
ctrl
lalt
lmeta
space
rmeta
ralt