Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too small queue size causing overflow.
✗ Incorrect
The queue size should be large enough to hold all nodes. Using 1000 ensures enough space for BFS.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking wrong node as visited.
✗ Incorrect
We mark the node at the front of the queue as visited after dequeuing it.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding at front index causing overwrite.
✗ Incorrect
We add the neighbor at the rear of the queue before incrementing rear.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting rear to 0 causes off-by-one errors.
✗ Incorrect
Front starts at 0 and rear starts at -1 before any elements are enqueued.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using rear as dequeue index.
✗ Incorrect
The BFS loop runs while front <= rear. We dequeue from queue[front].