Question DSA-GRAPH-0008
MediumWhat is the output of this code?
g = {0: [1, 2], 1: [3], 2: [3], 3: [4], 4: []}
from collections import deque
seen, q, order = {0}, deque([0]), []
while q:
u = q.popleft()
order.append(u)
for v in g[u]:
if v not in seen:
seen.add(v)
q.append(v)
print(order)
- A.
[0, 1, 3, 4, 2]
- B.
[0, 1, 2, 3, 4]
- C.
Sign up free to see the answer and a step-by-step explanation.