Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a queue node pointer for BFS traversal.
DSA C
struct QueueNode* [1] = NULL;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'root' as queue pointer instead of 'front'.
Using a temporary variable name that does not represent queue front.
✗ Incorrect
The queue front pointer is commonly named 'front' to track the start of the queue.
2fill in blank
mediumComplete the code to enqueue a binary tree node into the queue.
DSA C
enqueue(queue, [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Enqueuing NULL instead of a valid node.
Enqueuing children before the current node.
✗ Incorrect
We enqueue the current node itself to start BFS traversal.
3fill in blank
hardFix the error in the condition to check if the queue is empty.
DSA C
while ([1] != NULL) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'rear' instead of 'front' for emptiness.
Checking 'root' which is unrelated to queue state.
✗ Incorrect
The queue is empty when 'front' is NULL, so we loop while 'front' is not NULL.
4fill in blank
hardFill both blanks to calculate the width of the current level.
DSA C
int width = [1] - [2] + 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using level or count instead of node indices.
Subtracting leftIndex from rightIndex without adding 1.
✗ Incorrect
Width is calculated as rightmost index minus leftmost index plus one.
5fill in blank
hardFill all three blanks to assign indices to child nodes during BFS.
DSA C
if (node->left) { enqueue(queue, node->left); node->left->index = [1] * 2 + [2]; } if (node->right) { enqueue(queue, node->right); node->right->index = [3] * 2 + 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using level instead of parent's index.
Using +1 for left child index instead of +0.
✗ Incorrect
Left child's index = parent's index * 2 + 0; right child's index = parent's index * 2 + 1.
