adjacent(G, u, v): bool
neighbors(G, u): set
add_vertex(G, u)
remove_vertex(G, u)
add_edge(G, u, v)
remove_edge(G, u, v)
adjacent
e neighbors
u
em $L{i-1}$
from collections import deque as Queue
def bfs(G, s):
visited = set()
queue = Queue()
queue.append(s)
while queue:
u = queue.popleft()
for v in neighbor(G, u):
if v not in visited:
queue.append(v)
visited.add(u)
def dfs(G, s):
visited = set()
queue = list()
queue.append(s)
while queue:
u = queue.pop()
for v in neighbor(G, u):
if v not in visited:
q.append(v)
visited.add(u)