Back to problems

Multi-source BFS

Algorithm · Amazon · Medium

For a graph that begins with several starting vertices, apply multi-source breadth-first search (BFS) to compute the minimum distance from any starting vertex to every other vertex. Implement the approach and explain how it works. Requirements: The input contains a node list, an edge list whose entries are node pairs, and a collection of starting nodes. Return a dictionary that maps every node to its minimum path distance. Input Constraints: The graph contains at most 10^4…

Checking your access…