0% found this document useful (0 votes)
278 views

Project Doc Dijkstra's Shortest Path

Dijkstra's algorithm, conceived by computer scientist Edsger Dijkstra in 1956 and published in 1959,[1][2] is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge path costs, producing a shortest path tree. This algorithm is often used in routing and as a subroutine in other graph algorithms. For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First). Dijkstra's original algorithm does not use a min-priority queue and runs in O(|V|^2) (where |V| is the number of vertices). The idea of this algorithm is also given in (Leyzorek et al. 1957). The implementation based on a min-priority queue implemented by a Fibonacci heap and running in O(|E|+|V|\log|V|) (where |E| is the number of edges) is due to (Fredman & Tarjan 1984). This is asymptotically the fastest known single-source shortest-path algorithm for arbitrary directed graphs with unbounded non-negative weights.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views

Project Doc Dijkstra's Shortest Path

Dijkstra's algorithm, conceived by computer scientist Edsger Dijkstra in 1956 and published in 1959,[1][2] is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge path costs, producing a shortest path tree. This algorithm is often used in routing and as a subroutine in other graph algorithms. For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First). Dijkstra's original algorithm does not use a min-priority queue and runs in O(|V|^2) (where |V| is the number of vertices). The idea of this algorithm is also given in (Leyzorek et al. 1957). The implementation based on a min-priority queue implemented by a Fibonacci heap and running in O(|E|+|V|\log|V|) (where |E| is the number of edges) is due to (Fredman & Tarjan 1984). This is asymptotically the fastest known single-source shortest-path algorithm for arbitrary directed graphs with unbounded non-negative weights.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PROJECT IN DISCRETE MATHEMATICS (MATH 110)

DIJKSTRAS SHORTEST PATH ALGORITHM

Submitted by: Rosales, Eldhie Ann Sabanal, Karen Balala, Kvin BSCpE 2

Submitted to: Engr. Roland Taganahan Instructor

ALGORITHM Print out the graph with its vertices name. Input the value of its edges. Show the possible path. Print out the value of the shortest path.

Source Code #include<iostream> using namespace std; int main() { int e1, e2, e3, e4, e5,e6; int p1, p2, p3, p4; cout<<"Dijkstra's Shortest Path Algorithm cout<<" c * cout<<" * * * cout<<" * * * cout<<" * * * cout<<" * * * cout<<" a * * * b cout<<" * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * * * * * cout<<" * d* * cout<<" * * cout<<" * * * * * *

\n\n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n"; \n\n";

cout<<" The program will find the shortest possible path in the graph from a to b.\n"; cout<<"Enter the value of edges:\n"; cout<<"\ta->c: "; cin>>e1; cout<<"\tc->b: "; cin>>e2; cout<<"\ta->d: "; cin>>e3; cout<<"\tc->d: "; cin>>e4; cout<<"\td->b: "; cin>>e5; cout<<"\ta->b: "; cin>>e6; p1=e1+e2; p2=e3+e5; p3=e1+e4+e5; p4=e2+e3+e4;

cout<<"There are five possible path:\n"; cout<<" a, c, b\n"; cout<<" a, d, b\n"; cout<<" a, c, d, b\n"; cout<<" a, d, c. b\n"; cout<<" a to b\n\n"; if ((p1<p2)&&(p1<p3)&&(p1<p4)&&(p1<e6)) cout<<"The shortest path is "<<p1<<".It passes through the vertices of a, c, b."<<endl; else if ((p2<p1)&&(p2<p3)&&(p2<p4)&&(p2<e6)) cout<<"The shortest path is "<<p2<<".It passes through the vertices of a, d, b."<<endl; else if ((p3<p1)&&(p3<p2)&&(p3<p4)&&(p3<e6)) cout<<"The shortest path is "<<p3<<". It passes through the vertices of a, c, d, b."<<endl; else if ((p4<p1)&&(p4<p2)&&(p4<p3)&&(p4<e6)) cout<<"The shortest path is "<<p4<<". It passes through the vertices of a, d, c. b."<<endl; else if ((e6<p1)&&(e6<p2)&&(e6<p3)&&(e6<p4)) cout<<"The shortest path is "<<e6<<".It passes through the vertices of a to b."<<endl; return 0; }

OUTPUT

You might also like