Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add the starting node to the queue.
DSA Python
queue = []
queue.[1](start)Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() instead of append() which removes an element.
Using remove() which deletes a specific element.
Using insert() without specifying the index.
✗ Incorrect
We use append() to add the starting node to the end of the queue for BFS.
2fill in blank
mediumComplete the code to dequeue the first element from the queue.
DSA Python
current = queue.[1](0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() which adds instead of removes.
Using remove() which removes by value, not index.
Using insert() which adds elements.
✗ Incorrect
pop(0) removes and returns the first element from the queue.
3fill in blank
hardFix the error in checking if a neighbor has been visited.
DSA Python
if neighbor not in [1]:
Attempts:
3 left
💡 Hint
Common Mistakes
Checking in queue instead of visited.
Checking in graph which contains all nodes.
Checking in current which is a single node.
✗ Incorrect
We check if neighbor is not in visited to avoid revisiting nodes.
4fill in blank
hardFill both blanks to update the distance and add neighbor to the queue.
DSA Python
distance[neighbor] = distance[current] [1] 1 queue.[2](neighbor)
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' which decreases distance.
Using pop() instead of append() which removes elements.
✗ Incorrect
We add 1 to the current node's distance and append the neighbor to the queue.
5fill in blank
hardFill all three blanks to initialize the BFS data structures.
DSA Python
visited = set() distance = [1]() queue = [] visited.[2](start) distance[start] = [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using list() instead of dict() for distance.
Using append() instead of add() for set.
Setting start distance to 1 instead of 0.
✗ Incorrect
We use dict() for distance, add() to mark visited, and 0 as start distance.
