0
0
DSA Goprogramming~10 mins

Tree Traversal Level Order BFS in DSA Go - 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 with the root node.

DSA Go
queue := []*TreeNode[1]
Drag options to blanks, or click blank then click option'
ATreeNode{}
Bnil
Croot
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing queue as empty instead of with root node
Using nil instead of root
Using an empty struct instead of the root pointer
2fill in blank
medium

Complete the code to dequeue the first node from the queue.

DSA Go
node := queue[[1]]
queue = queue[1:]
Drag options to blanks, or click blank then click option'
A0
B1
C-1
Dlen(queue)
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 which skips the first element
Using negative index which is invalid
Using length of queue which is out of range
3fill in blank
hard

Fix the error in the code to add the left child to the queue only if it exists.

DSA Go
if node.Left [1] nil {
    queue = append(queue, node.Left)
}
Drag options to blanks, or click blank then click option'
A>
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if left child is equal to nil instead of not equal
Using comparison operators like < or > which are invalid for pointers
4fill in blank
hard

Fill both blanks to add the right child to the queue only if it exists and continue the loop.

DSA Go
if node.Right [1] nil {
    queue = append(queue, node.Right)
}
[2]
Drag options to blanks, or click blank then click option'
A!=
B==
Ccontinue
Dbreak
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' to check for nil
Using 'break' instead of 'continue' which stops the loop
5fill in blank
hard

Fill all three blanks to complete the BFS loop that processes nodes until the queue is empty.

DSA Go
for len(queue) [1] 0 {
    node := queue[[2]]
    queue = queue[[3]:]
    // process node
}
Drag options to blanks, or click blank then click option'
A>
B0
C1
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in loop condition
Using wrong indices for dequeue and slicing