# Graph Theory/Weighted graphs and algorithms

This page was last edited 17 months ago, and may be abandonedThis page has not been edited since 9 September 2018, but other pages in this book might have been. Check out related changes to see what the state of this book is. You can help by editing and updating this book. Remove {{under construction}} from this page if it is not being actively edited. Ask for help at WB:PROJECTS. |

**Algorithm (Dijkstra's algorithm)**:

Let be a finite digraph with weight . Fix a node . Then the following algorithm computes a shortest path from any node other than to :

In C, the graph and the function shall be given by the nodes (where and ) and a weight function `double long weight(int source, int target)`

which is whenever `source`

and `target`

are not incident.

```
1 boolean nextStep[n];
2 int nextStepLength;
3
4 nextStepLength = 1;
5 for(k=0;k<n;k++) {
6 nextStep[k] = k;
7 }
8
9 int step;
10 int vNo;
11 for(step=0;step<n;step++) {
12 for(vNo = 0; vNo < nextStepLength; vNo++) {
13
14 }
15 }
```