0
0
DSA Cprogramming~10 mins

Floyd Warshall All Pairs Shortest Path in DSA C - 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 distance matrix with the given graph weights.

DSA C
for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
        dist[i][j] = graph[i][j];
        if (i == j) {
            dist[i][j] = [1];
        }
    }
}
Drag options to blanks, or click blank then click option'
A0
B1
C-1
D9999
Attempts:
3 left
💡 Hint
Common Mistakes
Setting distance to 1 instead of 0 for same vertices.
Using a large number instead of zero.
2fill in blank
medium

Complete the code to update the distance if a shorter path is found through vertex k.

DSA C
if (dist[i][k] != INF && dist[k][j] != INF && dist[i][k] + dist[k][j] < [1]) {
    dist[i][j] = dist[i][k] + dist[k][j];
}
Drag options to blanks, or click blank then click option'
Adist[i][j]
Bdist[i][k]
Cdist[k][j]
DINF
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with dist[i][k] or dist[k][j] instead of dist[i][j].
Using INF in the comparison incorrectly.
3fill in blank
hard

Fix the error in the nested loops to correctly iterate over all vertices.

DSA C
for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < [1]; j++) {
            // update dist[i][j]
        }
    }
}
Drag options to blanks, or click blank then click option'
Aj
BV
Ck
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using loop variables k, i, or j as loop limits instead of V.
Setting incorrect loop boundaries causing incomplete iteration.
4fill in blank
hard

Fill both blanks to correctly print the final distance matrix after Floyd Warshall algorithm.

DSA C
for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
        if (dist[i][j] == [1])
            printf("%s ", "INF");
        else
            printf("%d ", [2]);
    }
    printf("\n");
}
Drag options to blanks, or click blank then click option'
AINF
Bdist[i][j]
Ci
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Printing loop variables instead of distance values.
Not checking for INF before printing.
5fill in blank
hard

Fill all three blanks to complete the Floyd Warshall update step inside the triple nested loops.

DSA C
if (dist[i][[1]] != INF && dist[[2]][j] != INF && dist[i][[3]] + dist[[2]][j] < dist[i][j]) {
    dist[i][j] = dist[i][[3]] + dist[[2]][j];
}
Drag options to blanks, or click blank then click option'
Ak
Bi
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables instead of k.
Mixing up indices causing wrong distance checks.