Skip to content
StackDecode
GraphsExplained

Multi-source BFS

Start the queue with several sources at once.

Time

O(V + E)

Extra space

O(V)

Use it for

Distance to the nearest source, spreading fire or rot.

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.