0
0
DSA Cprogramming~10 mins

BFS Breadth First Search on Graph 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 initialize the queue front index.

DSA C
int front = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing front to -1 causes invalid array access like queue[front].
Using NULL is invalid for integer index.
2fill in blank
medium

Complete the code to enqueue a vertex into the queue.

DSA C
queue[++rear] = [1];
Drag options to blanks, or click blank then click option'
Avertex
Bvisited
Cadjacency
Dfront
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.
3fill in blank
medium

Fix 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'
A<
B>
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' misses the last element in the queue.
Using '==' only runs once and stops prematurely.
4fill in blank
hard

Fill 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'
A1
B0
Cadjacency[i]
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Setting visited to 0 means not visited.
Enqueueing 'i' instead of adjacency[i] adds wrong vertex.
5fill in blank
hard

Fill 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'
Afront
B<
Crear + 1
Drear
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from front + 1 skips first element.
Using '<=' with rear + 1 causes out-of-bound access.