Complete the code to initialize the queue for BFS traversal.
Queue<int> queue = new Queue<int>();
queue.[1](start);In C#, the method to add an element to a queue is Enqueue.
Complete the code to mark the start node as visited.
bool[] visited = new bool[n];
visited[[1]] = true;We mark the start node as visited to avoid revisiting it.
Fix the error in the BFS loop condition to continue while the queue is not empty.
while (queue.[1] > 0) { int current = queue.Dequeue(); // process neighbors }
The Count property gives the number of elements in the queue.
Fill both blanks to update the distance and enqueue the neighbor node.
if (!visited[neighbor]) { visited[neighbor] = true; distance[neighbor] = distance[[1]] + 1; queue.[2](neighbor); }
Distance of neighbor is one more than current node's distance, and we add neighbor to the queue using Enqueue.
Fill all three blanks to reconstruct the shortest path from end to start.
List<int> path = new List<int>(); int node = end; while (node != [1]) { path.[2](node); node = parent[[3]]; } path.Add(start); path.Reverse();
We loop until we reach the start node, add nodes to path using Add, and update node to its parent.
