0
0
DSA Cprogramming~10 mins

Connected Components Using BFS in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the queue size for BFS traversal.

DSA C
int queue[[1]];
Drag options to blanks, or click blank then click option'
A-1
B10
C0
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using too small queue size causing overflow.
2fill in blank
medium

Complete the code to mark a node as visited inside BFS.

DSA C
visited[[1]] = 1;
Drag options to blanks, or click blank then click option'
Anode
Bqueue[rear]
Ci
Dqueue[front]
Attempts:
3 left
💡 Hint
Common Mistakes
Marking wrong node as visited.
3fill in blank
hard

Fix the error in the BFS enqueue operation to add neighbors.

DSA C
if(adj[node][i] == 1 && visited[i] == 0) {
    queue[[1]] = i;
    rear++;
    visited[i] = 1;
}
Drag options to blanks, or click blank then click option'
Ai
Bnode
Crear
Dfront
Attempts:
3 left
💡 Hint
Common Mistakes
Adding at front index causing overwrite.
4fill in blank
hard

Fill both blanks to correctly initialize BFS queue pointers.

DSA C
int front = [1];
int rear = [2];
Drag options to blanks, or click blank then click option'
A0
B-1
C1
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting rear to 0 causes off-by-one errors.
5fill in blank
hard

Fill all three blanks to complete the BFS loop condition and dequeue operation.

DSA C
while([1] <= [2]) {
    int node = queue[[3]];
    front++;
    // process node
}
Drag options to blanks, or click blank then click option'
Arear
Bfront
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using rear as dequeue index.