No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Dijkstra's Greedy Routing Algorithm

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

1.9 | 15 ratings Rate this file 6 Downloads (last 30 days) File Size: 3.53 KB File ID: #5543 Version: 1.0

Dijkstra's Greedy Routing Algorithm


Kashif Shahzad (view profile)


22 Jul 2004 (Updated )

A routing algorithm to compute the shortest path between nodes.

| Watch this File

File Information

This time it's a well commented program for better understanding.

MATLAB release MATLAB 6.5 (R13)
Other requirements nopes
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
04 May 2016 Inam Khan

I am Inam Ullah Khan from Pakistan.I have BS(Computer Science) 4 years degree and nw a days doing MS(Electronic Engineering) and my research area is Route Optimization with Ant Colony Optimization and in Route optimization i am using Bellman ford, Brute Force and Dijikstra Algorithm.And i need comparison graphs in terms of time and delay.
Please I need more information about my research and the related topics. Thank you.
Best Regards
Inam Ullah Khan

Comment only
17 May 2008 sweety swa  
13 Jan 2008 adam smith

You should improve it. It is so basic !!!
And works only for 26 node

15 Oct 2007 Abdul-Kareem A. R. Shukri Alam

I am Abdul-Kareem from Iraq. I have BSc in computer since and BSc in electrical engineering. Now I am student in computer engineering to get MSc degree in Information Technology engineering. My research is "Design and Implementation a Multicast Routing Algorithm for a Network".
Please I need more information about my research and the related topics. Thank you.
Best regards.

Comment only
05 Apr 2007 Debabrata Nag

The key concept for dijkstra algorithm is Relaxation.While the code does the initialization and selection the relaxation part is wrongly done as it requires comparison between the current value at a node and that obtained by relaxation......just simply changing the value in iterations leads nowhere........

01 Mar 2007 José Estrada Soto  
20 May 2005 Graeme Doole

This algorithm is an incorrect formulation of the Dijkstra method.

02 May 2005 Sungkwan Youm

this implementation is wrong, the code must be improved.

07 Jan 2005 Qing Lee

This is dijkstra algorithm?

06 Dec 2004 Andre Jellema

I think Dijkstra's algorithm is implemented wrongly

26 Oct 2004 Milena Vasquez

very good

26 Aug 2004 Vann Hills

Funny implementation!

11 Aug 2004 Brown Zu

This code is so confusing. It should not be titled as "Dijkstra routing". It seems that the author doesn't know what routing is, and what Dijkstra algorithm is.

11 Aug 2004 Brown Zu

This code is so confusing. It should be titled as "Dijkstra routing". It seems that the author doesn't know what routing is, and what Dijkstra algorithm is.

30 Jul 2004 Tim Benhart

It is interesting to compare the two implementations of Dijkstra routing here. I borrow some codes from the other one, and shows the route found using this code. It clearly shows that this code doesn't work.

noOfNodes = 50;
rand('state', 0);
hold on;
L = 1000;
R = 200; % maximum range;
netXloc = rand(1,noOfNodes)*L;
netYloc = rand(1,noOfNodes)*L;
for i = 1:noOfNodes
plot(netXloc(i), netYloc(i), '.');
text(netXloc(i), netYloc(i), num2str(i));
for j = 1:noOfNodes
distance = sqrt((netXloc(i) - netXloc(j))^2 + (netYloc(i) - netYloc(j))^2);
if distance <= R
matrix(i, j) = 1; % there is a link;
line([netXloc(i) netXloc(j)], [netYloc(i) netYloc(j)], 'LineStyle', ':');
matrix(i, j) = inf;

activeNodes = [];
for i = 1:noOfNodes,
% initialize the farthest node to be itself;
farthestPreviousHop(i) = i; % used to compute the RTS/CTS range;
farthestNextHop(i) = i;

n = noOfNodes

for p=1:n

% Taking input from user regarding source & destination nodes

s = 1
d = 15;

% converting source node to status PERMANANT

% if (adj(s,t)==0)
% disp('Source and Destination are Same');
% continue
% end

adj = matrix;
% Main algorithm of Greedy Dijkstra
for k=1:inf
for h=1:n
if a(h).status==0 % If Unknown
temp=[temp adj(s,h)];
temp=[temp inf];
acc=[acc aa];
path=[path s];
if s==d


if length(path) ~= 0
for i = 1:(length(path)-1)
line([netXloc(path(i)) netXloc(path(i+1))], [netYloc(path(i)) netYloc(path(i+1))], 'Color','r','LineWidth', 0.50, 'LineStyle', '-.');
hold off;

Comment only
30 Jul 2004 Clive Loyld

I have tried it and it woked pretty ok, but author should have done one thing, nodes weights are taken as [A][B] etc while source and destination are taken as 1, 2, , u improve it, but still it works fine

29 Jul 2004 Bunzo Akamatsu

Agree. This implementation is really funny! I can't see where routing is performed.
There are bunch of codes on routing on Internet. The author at least should take a look at other implementations.

28 Jul 2004 Avinash Jain

This code cannot do routing at all.
I input the weights, but the program did not return anything.
I do not think by just choosing the closest neighbor can do routing.
Please tell me if I am wrong.

Contact us