Search Wiki:
Resource Page Description
You may have read about Dijkstra's algorithm (http://en.wikipedia.org/wiki/Dijkstra's_algorithm ) but I am going to show the smallest code ever.

In this code 3 components are involved.
int NodeIndex[NumberOfNodes];
int MinimumDistance[NumberOfNodes];
int int[NumberOfNodes, NumberOfNodes] data;

Please see the attached file (Dijkstra.txt) for the code.

You may have read about Dijkstra's algorithm (http://en.wikipedia.org/wiki/Dijkstra's_algorithm ) but I am going to show the smallest code ever.
In this code 3 components are involved.
int NodeIndexNumberOfNodes;
int MinimumDistanceNumberOfNodes;
int intNumberOfNodes, NumberOfNodes data;

In NodeIndex buffer we mark index with -1 where we have visited the node.
In MinimumDistance we keep the weight from start node. If node is not connected we set to -1. We will irritate to the all nodes until we reach the last node. To keep it simple we are going to keep only 4 nodes (Node A to Node D).

A B C D
A -1 2 4 -1
B 2 -1 -1 5
C 4 -1 -1 3
D -1 5 3 -1

You may draw it with attached program. Please see the help file how to use it.
NumberOfNodes = 4;
NodeIndex[] = {-1,1,2,3};
MinimumDistance[] = {-1,2,4,-1}; // first row of data. We always start with node 1, because node 0 is already filled.


Last edited Feb 23 2012 at 4:01 AM  by Agha_Khan, version 2
Updating...
Page view tracker