Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the queue for BFS traversal.
DSA C
Queue* queue = [1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using stack initialization instead of queue.
Using list or array initialization which is not suitable here.
✗ Incorrect
We need to create a queue to perform BFS. The function createQueue initializes it.
2fill in blank
mediumComplete the code to check if the queue is empty during traversal.
DSA C
while () {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if queue is full instead of empty.
Using incorrect function names.
✗ Incorrect
We continue traversal while the queue is not empty, so we check with isEmpty.
3fill in blank
hardFix the error in the code to correctly pop the front node from the queue.
DSA C
TreeNode* node = [1](queue);Attempts:
3 left
💡 Hint
Common Mistakes
Using stack pop instead of queue dequeue.
Using peek which does not remove the element.
✗ Incorrect
To remove and get the front element from the queue, we use dequeue.
4fill in blank
hardFill both blanks to correctly reverse the order of nodes at odd levels.
DSA C
if (level % 2 == 1) { reverseArray([1], [2]); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for array or size.
Reversing at even levels instead of odd.
✗ Incorrect
We reverse the array currentLevelNodes of length nodeCount at odd levels.
5fill in blank
hardFill all three blanks to correctly add child nodes to the queue during traversal.
DSA C
if (node->left != NULL) { [1](queue, node->[2]); } if (node->right != NULL) { [3](queue, node->right); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of enqueue for queue.
Accessing wrong child pointers.
✗ Incorrect
We enqueue left and right child nodes to the queue for BFS traversal.
