Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the queue with the start node.
DSA Typescript
const queue: number[] = [[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of the start node variable.
Using the whole graph or visited array instead of a single node.
✗ Incorrect
We start BFS by adding the start node to the queue.
2fill in blank
mediumComplete the code to mark the start node as visited.
DSA Typescript
visited[[1]] = true; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking index 0 instead of the start node.
Marking the whole queue or node variable incorrectly.
✗ Incorrect
We mark the start node as visited to avoid revisiting it.
3fill in blank
hardFix the error in the loop condition to process nodes until the queue is empty.
DSA Typescript
while (queue.[1] > 0) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or count which are not valid for arrays.
Using length() as a function instead of a property.
✗ Incorrect
The length property gives the number of elements in the queue array.
4fill in blank
hardFill both blanks to correctly update the distance for neighbors and add them to the queue.
DSA Typescript
distance[neighbor] = distance[current] [1] 1; queue.[2](neighbor);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' for distance update.
Using pop instead of push to add neighbors.
✗ Incorrect
We add 1 to the current node's distance for the neighbor and push the neighbor to the queue.
5fill in blank
hardFill all three blanks to correctly check neighbors and update visited and distance arrays.
DSA Typescript
if (!visited[[1]]) { visited[[2]] = true; distance[[3]] = distance[current] + 1; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using current or start instead of neighbor in visited or distance updates.
Marking visited or updating distance for the wrong node.
✗ Incorrect
We check if neighbor is not visited, mark neighbor visited, and update neighbor's distance.