Complete the code to initialize the queue for BFS traversal.
Queue<int> queue = new Queue<int>();
queue.[1](startNode);The Enqueue method adds an element to the end of the queue, which is needed to start BFS.
Complete the code to dequeue the next node in BFS.
int current = queue.[1]();The Dequeue method removes and returns the element at the front of the queue, which is needed to process nodes in BFS order.
Fix the error in the BFS loop condition to continue while the queue is not empty.
while (queue.[1] > 0) { // BFS logic }
The Count property gives the number of elements in the queue. We continue while it is greater than zero.
Fill both blanks to check if a neighbor node is not visited and then mark it visited.
if (visited[neighbor][1]) { visited[neighbor] = [2]; queue.Enqueue(neighbor); }
The condition visited[neighbor] == false checks if the neighbor is not visited. Then we mark it visited by setting true.
Fill all three blanks to complete the BFS method signature and initialize the visited array.
public void BFS(int [1], List<int>[] [2]) { bool[] visited = new bool[[3]]; // BFS logic }
The method takes a starting node startNode and a graph represented as an adjacency list graph. The visited array size is the number of nodes, which is graph.Length.
