Complete the code to initialize the distance array with infinity.
for (int i = 0; i < V; i++) { dist[i] = [1]; }
We use INT_MAX to represent infinity for initial distances.
Complete the code to pick the vertex with the minimum distance value not yet processed.
int minDistance(int dist[], bool sptSet[]) {
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++) {
if (sptSet[v] == false && dist[v] [1] min) {
min = dist[v];
min_index = v;
}
}
return min_index;
}We look for the vertex with the smallest distance value, so we use <.
Fix the error in the condition to update the distance of adjacent vertices.
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] [1] dist[v]) { dist[v] = dist[u] + graph[u][v]; }
We update the distance if the new path is shorter, so use <.
Fill both blanks to complete the loop that runs Dijkstra's algorithm for all vertices.
for (int count = 0; count [1] V - 1; count++) { int u = [2](dist, sptSet); sptSet[u] = true; // Update dist values }
The loop runs while count is less than V-1, and minDistance picks the next vertex.
Fill all three blanks to complete the code that prints the shortest distances from the source.
void printSolution(int dist[], int n) {
printf("Vertex \t Distance from Source\n");
for (int [1] = 0; [1] < [2]; [1]++) {
printf("%d \t\t %d\n", [3], dist[[1]]);
}
}Use i as the loop variable, loop until n, and print using i.
