Skip to content
StackDecode
GraphsExplained

0-1 BFS

BFS with a deque: 0-weight edges to the front, 1-weight to the back.

Time

O(V + E)

Extra space

O(V)

Use it for

Graphs whose edges weigh 0 or 1.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.