Breadth-First Search & Degrees of Separation
In short: breadth-first search (BFS) explores a graph outward one ring at a time — everyone one hop away, then everyone two hops away — using a queue (first in, first out) and a visited set so nobody is explored twice. Because it never skips ahead to a farther ring, the first time BFS reaches a vertex is always along a shortest possible route — which is why it powers degrees of separation, "people you may know", maze solvers and any "fewest steps" question on an unweighted graph. Cost: O(V + E) time, O(V) memory for the queue and visited set.

Degrees of separation on Tunebox
Ana opens Dia's profile and Tunebox says 2nd-degree connection. Working that out means rippling outward from Ana, ring by ring, until Dia turns up:
BFS spreads out in rings, and a listener's ring is fixed the first time the walk reaches them.
Ring 0 is Ana alone, zero hops from herself. 5 nodes, 6 edges, directed. At ana. Frontier: ana. ana: 0.
Classic BFS keeps that ripple with one queue instead of explicit rings: discoveries join the back, you explore from the front, so everything closer is explored before anything farther:
Names join at the back and leave from the front, so every ring-1 name leaves before any ring-2 name.
The search starts with Ana alone in the queue. Queue, 1 item. Head is ana, tail is ana.
from collections import deque
queue = deque(["ana"])
queue.append("ben")
queue.append("cal")
print(queue.popleft(), queue.pop())❓ Cross-question — "Why
deque? A list hasappendandpop(0)." It does, butlist.pop(0)shifts every remaining item left — O(n) per call — so BFS over a big graph quietly turns quadratic.deque.popleft()is O(1).
The mistake: marking a listener seen when they leave the queue instead of when they join it. Dia gets queued once by Ben and again by Cal, because neither visit has "left" yet when the other happens:
Each listener should appear once, but Dia appears twice. Fix where the visited set is updated.