dijkstra 27s weighted graph shortest path in c 2b 2b

Solutions on MaxInterview for dijkstra 27s weighted graph shortest path in c 2b 2b by the best coders in the world

showing results for - "dijkstra 27s weighted graph shortest path in c 2b 2b"
Eric
06 Jan 2019
1#include <limits.h> 
2#include <stdio.h> 
3  
4
5#define V 9 
6  
7
8int minDistance(int dist[], bool sptSet[]) 
9{ 
10
11    int min = INT_MAX, min_index; 
12  
13    for (int v = 0; v < V; v++) 
14        if (sptSet[v] == false && dist[v] <= min) 
15            min = dist[v], min_index = v; 
16  
17    return min_index; 
18} 
19  
20
21void printSolution(int dist[]) 
22{ 
23    printf("Vertex \t\t Distance from Source\n"); 
24    for (int i = 0; i < V; i++) 
25        printf("%d \t\t %d\n", i, dist[i]); 
26} 
27  
28
29void dijkstra(int graph[V][V], int src) 
30{ 
31    int dist[V]; 
32    
33  
34    bool sptSet[V];
35 
36    for (int i = 0; i < V; i++) 
37        dist[i] = INT_MAX, sptSet[i] = false; 
38  
39  
40    dist[src] = 0; 
41  
42  
43    for (int count = 0; count < V - 1; count++) { 
44       
45        int u = minDistance(dist, sptSet); 
46  
47       
48        sptSet[u] = true; 
49  
50       
51        for (int v = 0; v < V; v++) 
52  
53           
54            if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX 
55                && dist[u] + graph[u][v] < dist[v]) 
56                dist[v] = dist[u] + graph[u][v]; 
57    } 
58  
59 
60    printSolution(dist); 
61} 
62  
63
64int main() 
65{ 
66    
67    int graph[V][V] = { { 0, 4, 0, 0, 0, 0, 0, 8, 0 }, 
68                        { 4, 0, 8, 0, 0, 0, 0, 11, 0 }, 
69                        { 0, 8, 0, 7, 0, 4, 0, 0, 2 }, 
70                        { 0, 0, 7, 0, 9, 14, 0, 0, 0 }, 
71                        { 0, 0, 0, 9, 0, 10, 0, 0, 0 }, 
72                        { 0, 0, 4, 14, 10, 0, 2, 0, 0 }, 
73                        { 0, 0, 0, 0, 0, 2, 0, 1, 6 }, 
74                        { 8, 11, 0, 0, 0, 0, 1, 0, 7 }, 
75                        { 0, 0, 2, 0, 0, 0, 6, 7, 0 } }; 
76  
77    dijkstra(graph, 0); 
78  
79    return 0; 
80} 
queries leading to this page
dijkstra algorithm codedijkstra algorithm for weighted graphsingle source shortest path algorithm geeksforgeeksshortest path algorithmdijkstra e2 80 99s algorithmimplement dijkstra 27s algorithm for computing shortest paths in a directed graphdijkstra algorithm c 2b 2bdijkstra on directed graphdijkstra 27sdijkstra weigthed graphwe discussed solving the single source shortest path problem with dijkstra 27s algorithmdijkstra 27s algorithmdijkstra algorithm for finding shortest path in c 2b 2b stl in directed graphfrom a given vertex of graph find shortest path using dijkstra algorithmwhich among the following be used to dijkstra shortest path algorithmwhen to use dijijkstra in graphdijkstra 27s algorithm weighted graph javadijkstras algorithm cpppresent and explain the dijkstra e2 80 99s algorithm to find the shortest path for the following weighted graph find shortest path in graph using dijkstra algorithmc program to find the shortest path using dijkstra e2 80 99s algorithm for a weighted connected graphsingle source shortest pathdijkstra algorithm 2c stepsdijkstra algorithm to find shortest path to a leaf in the given graphdijkstra shortest path froma weighted graph turn basedijkstra algorith c 2b 2bhow to solve shortest path problem in c 2b 2bprint shortest path dijkstrashortest path algorithm weighted graphshortest path dijkstra c 2b 2bweighted directed graph dijkstra algorithm to find shortest path using adj listdijakstra algorithm weighted directed graph dijkstra algorithm to find shortest path dijktsra 27s shortest weighted path algorithmdijkstras algorithmuse dijkstra e2 80 99s algorithm to find the shortest path from 28a 26 c 29 to all nodes djikstra algorithmsingle source shortest path problemdijkstra algorithm c 2b 2b codehow can i modify dijkstra 27s algorithm to find the shortest path in a graph with weighted edges and weighted vertices 3fdijkstra 27s algorithm c 2b 2bwhat will be the running time of dijkstra 27s single sourceprocedure for shortest path of a graph using dijkstra algorithm in c 2b 2bshortest path algorithm for directed graphdykstras algorithmwe discussed solving the single source shortest path problem with dijkstra 27s algorithdijkstra 27s algorithm in c 2b 2bdijkstrahow to find shortest path using dijkstra c 2b 2bdijkstra algorithm stepsdijkstra algorithm in cdijkstra algorithmdijkashtra algorithmdijkstra 27s shortest path algorithm directed graphdijkstra 27s weighted graph shortest path in c 2b 2bdijkstra 27s algorithm for weighted graphdijkstra algorithm for finding shortest path dijkstra 27s algorithm weighted graphdijkstra 27s weighted graph shortest path in c 2b 2b