Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the queue front index.
DSA C
int front = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing front to -1 causes invalid array access like queue[front].
Using NULL is invalid for integer index.
✗ Incorrect
The queue front index is initialized to 0 (with rear typically -1) to indicate the queue is empty.
2fill in blank
mediumComplete the code to enqueue a vertex into the queue.
DSA C
queue[++rear] = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'visited' instead of vertex causes wrong data in queue.
Using 'front' or 'adjacency' is incorrect for enqueue operation.
✗ Incorrect
We enqueue the current vertex by placing it at the rear of the queue.
3fill in blank
mediumFix the error in the BFS loop condition to continue while queue is not empty.
DSA C
while (front [1] rear) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' misses the last element in the queue.
Using '==' only runs once and stops prematurely.
✗ Incorrect
The loop continues while front is less than or equal to rear, meaning queue has elements.
4fill in blank
hardFill both blanks to mark a vertex as visited and enqueue it.
DSA C
if (!visited[adjacency[i]]) { visited[adjacency[i]] = [1]; queue[++rear] = [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting visited to 0 means not visited.
Enqueueing 'i' instead of adjacency[i] adds wrong vertex.
✗ Incorrect
Mark the adjacency vertex as visited by setting 1, then enqueue that vertex.
5fill in blank
hardFill all three blanks to print the BFS traversal order.
DSA C
for (int i = [1]; i [2] [3]; i++) { printf("%d ", queue[i]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from front + 1 skips first element.
Using '<=' with rear + 1 causes out-of-bound access.
✗ Incorrect
Start from front, go while i < rear + 1 to print all elements in queue.