Complete the code to initialize the visited array for BFS.
boolean[] visited = new boolean[[1]];The visited array size should match the number of nodes, which is graph.length.
Complete the code to add the starting node to the BFS queue.
Queue<Integer> queue = new LinkedList<>();
queue.[1](start);In Java's Queue interface, offer() adds an element to the queue safely.
Fix the error in the BFS loop condition to process nodes until the queue is empty.
while (!queue.[1]()) { int node = queue.poll(); // process node }
The correct method to check if a queue is empty is isEmpty().
Fill both blanks to mark a node visited and add its neighbors to the queue if unvisited.
visited[node] = [1]; for (int neighbor : graph[node]) { if (!visited[neighbor]) { queue.[2](neighbor); } }
Mark the node as visited by setting true, and add neighbors using offer() to the queue.
Fill all three blanks to complete the connected components count using BFS.
int count = 0; for (int i = 0; i < [1]; i++) { if (!visited[i]) { bfs(graph, i, visited); count [2] [3]; } }
Loop over all nodes using graph.length, increment count by 1 for each new component found.
