0
0
DSA Cprogramming~10 mins

Why Shortest Path Is a Graph Problem Not a Tree Problem in DSA C - Test Your Knowledge

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the graph adjacency list.

DSA C
int graph[[1]][[1]] = {0};
Drag options to blanks, or click blank then click option'
A10
B5
C50
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using a size too small for the graph nodes.
Confusing the size with the number of edges.
2fill in blank
medium

Complete the code to update the distance array for shortest path calculation.

DSA C
dist[i] = [1];
Drag options to blanks, or click blank then click option'
A0
B1
C-1
DINT_MAX
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing distances to 0, which is incorrect.
Using negative values which don't make sense for distances.
3fill in blank
hard

Fix the error in the loop condition to correctly iterate over graph nodes.

DSA C
for (int i = 0; i [1] n; i++) {
Drag options to blanks, or click blank then click option'
A<
B>
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= instead of < causing index errors.
Using > or >= which never enter the loop.
4fill in blank
hard

Fill both blanks to correctly check and update the shortest path distance.

DSA C
if (graph[u][v] != 0 && dist[u] != INT_MAX && dist[u] [1] dist[v] - graph[u][v]) {
    dist[v] = dist[u] [2] graph[u][v];
}
Drag options to blanks, or click blank then click option'
A<
B+
C>
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < in the condition.
Subtracting edge weight instead of adding.
5fill in blank
hard

Fill all three blanks to correctly implement the relaxation step in Dijkstra's algorithm.

DSA C
for (int v = 0; v [1] n; v++) {
    if (!visited[v] && graph[u][v] != 0 && dist[u] [2] graph[u][v] [3] dist[v]) {
        dist[v] = dist[u] + graph[u][v];
    }
}
Drag options to blanks, or click blank then click option'
A<=
B<
C+
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= instead of < in loop condition.
Using wrong comparison operators in if condition.