6
Loading subject content…
Loading subject content…
Loading practice questions…
What is the output of the following code?
from collections import deque
g = {1: [2, 3], 2: [4], 3: [4], 4: []}
seen, q, order = {1}, deque([1]), []
while q:
v = q.popleft()
order.append(v)
for w in g[v]:
if w not in seen:
seen.add(w)
q.append(w)
print(order)