Before running BFS, set up three data structures. First, a queue to hold nodes waiting to be processed. Start with an empty queue. Second, a visited array to track which nodes you have seen. Initialize all entries to false. Third, a distance array to record how far each node is from the source.
Set all distances to infinity except the source, which gets distance . These three structures work together: the queue controls the order, visited prevents cycles, and distance tracks shortest paths.