0
0
DSA Typescriptprogramming~10 mins

Shortest Path in Unweighted Graph Using BFS in DSA Typescript - 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 start node.

DSA Typescript
const queue: number[] = [[1]];
Drag options to blanks, or click blank then click option'
Astart
B0
Cgraph
Dvisited
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.
2fill in blank
medium

Complete the code to mark the start node as visited.

DSA Typescript
visited[[1]] = true;
Drag options to blanks, or click blank then click option'
Aqueue
B0
Cstart
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Marking index 0 instead of the start node.
Marking the whole queue or node variable incorrectly.
3fill in blank
hard

Fix 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'
Acount
Bsize
Clength()
Dlength
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.
4fill in blank
hard

Fill 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'
A+
B-
Cpush
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' for distance update.
Using pop instead of push to add neighbors.
5fill in blank
hard

Fill 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'
Aneighbor
Bcurrent
Dstart
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.