473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,405 developers and data experts.

The correctness of Dijkstra's Algorithm

Please see the attachment also!

Assumptions:
1>n nodes and m edges are there in the Graph V. V may directed or undirected both.
2>Weights of all the edges are non-negative finite numbers.

What the Dijkstra algorithm does:
------------------------
It finds all the shortest paths from a particular node s to all other vertexes.

How the Dijkstra algorithm does this:
----------------------------

At any point of time as the Algorithm runs we have 2 sets of nodes.
Set 1 has the nodes whose shortest paths from S has been discovered.
Set 2 has the nodes whose shortest paths are yet to be discovered.
Also node S has shortest path as 0.

So initially Set 1 only has a single node which is S. S has shortest path from S , which has distance 0.
We call 0 as Dijkstra score of S and denote it as D(S). We store this somewhere.

Now we inspect all the edges which cross from Set 1 to Set 2. We add D(S) to all these edges separately
and compare the results. The node V, which gives the smallest result as D(V), is included into Set 1 and excluded
from Set 2. D(V) is stored.

Similarly in the next step, all the edges from S or V which connect nodes of Set 2 are inspected separately.
Now we have 2 Dijkstra scores D(S) and D(V). So for the edges which have one end point with S
will be added to D(S) and the others will be added to D(V). The smallest result D(U) found where node is say U.
U is included in Set 1. U is excluded from Set 2. D(U) is stored.

This way the algorithm works. It stops as Set 2 is empty.
All the Dijkstra scores of the nodes are the shortest paths.


Correctness:
------------

We assume that when the (K+1)-th node is added to Set 1,
the Dijstra algorithm fails for the first time. That means that
(K+1)-th node is the first node which has the wrong shortest path from S.
We call the Dijkstra score of node K+1 as D(K+1).


So till Kth nodes all the dijkstra scores are really the shortest path.

We assume that the actual shortest path from S is not D(K+1). ---- Assumption 1

So there was an alternative path which was shorter. That means any node in this alternative
path has lesser distance from S, than value D(K+1). ---- Assumption 2

Again this alternative shortest path has somewhere crossed from Set 1 to Set 2.
Say this crossing edge connects node J. Evidently at least till J in this alternative path from S, all the nodes have their Dijkstra score as their shortest distance from S.

Here is the contradiction. From assumption 2, D(J) is always less than D(K+1).
So after K-th node was included in Set 1, K+1-th node can never be included
into Set 1 before node J. Because D(J) is less than D(K+1).

So Assumption 1 is wrong.

Attached Images
File Type: jpg Dijkstra_correctness.jpg (14.5 KB, 1174 views)
Aug 31 '13 #1
2 3949
kudos
127 Expert 100+
Ok, let me get this right?

This is your claim. You have a graph. You have two point, a start point and an end end point. You run Djikstras shortest path algorithm, so you find one the shortest path between the start and end point. Let's call this path A.

Then, you insert another node into the graph, and tell us that A is no longer the shortest path?

Have I understood the claim right? Then it is a bit unfair to the algorithm, don't you think?

Also

"It finds all the shortest paths from a particular node s to all other vertexes."

This is wrong, it find the shortest path between two points, not all of them. Finding for instance the shortest path between a start point and the rest of the vertices (shortest route) sounds like a different (and much harder) problem.
Sep 3 '13 #2
Hi Kudos,

Thanks for your comment.
Let me tell you that there was slight mistake in your understanding.

First thing is that I am not inserting any other node in the graph. It has n number of nodes from the biginning. This n is constant.

What the Algorithm is doing is that it is maintaining two disjoint subsets of nodes which we call Set 1 and Set 2.
Set 1 only maintains the nodes which have their shortest paths already calculated.
Initially Set 1 has 0 elements (nodes). Set 2 has n elements.
As the algorithm completes Set 1 has n elements and Set 2 has 0 elements.

secondly: I guess it computes all the shortest paths to other nodes from S. If there is a duplicate shortest path that won't be discovered.

Hope I am able to make it clear. Please let me know if there is any more confusion.

Regards
Sep 3 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
2
by: Jim Strathmeyer | last post by:
I have a weird question about const correctness when using an stl list. I have a wrapper Inventory class that holds a list of pointers to Items. (Yes, they have to be pointers.) Now, obviously...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
12
by: No Such Luck | last post by:
Hi All: I'm not sure if this is the right place to ask this question, but I couldn't find a more appropriate group. This is more of a theory question regarding an algorithm implemented in C, not...
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
4
by: Simon Biber | last post by:
I would appreciate some critique of the code below. I have attempted to avoid the undefined behaviour that would happen if pointers went off the beginning of the arrays. The boolean logic is rather...
10
by: Aris | last post by:
Hello! This is my problem. I'm trying to make an inorder traversal algorithm for a binary tree, not a recursive one, but using a stack. Till now I got this: void traverse(tree * p) { l:...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
4
by: thomasau | last post by:
Hi everyone ! Can someone point me to a good and simple implementation of the Dijkstras algorithm using C . Thanks! -Thomas
5
by: onkardesai | last post by:
#include<stdio.h> int main() { int a,b,w,v,e,i; int g,visited,d,p; printf("enter the number of vertices"); scanf("%d",&v); printf("enter the number of edges"); scanf("%d",&e);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.