0% found this document useful (0 votes)
9 views10 pages

Dijkstras

Uploaded by

izazu350
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Dijkstras

Uploaded by

izazu350
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Dijkstra's

Algorithm:
Exploring the
Shortest Path
Dijkstra's algorithm is a fundamental graph theory concept that helps find the
shortest path between two nodes in a weighted graph. It is widely used in various
applications, from transportation and logistics to network routing and social
network analysis.

Izaz Ul haq 15241


M.Hamaad 15156
Introduction to Dijkstra's
Algorithm
1 Start Node
The algorithm begins at a specified start node and explores
the surrounding edges to find the shortest paths.

Maintain Shortest
2 Paths
It keeps track of the current shortest distance to each node
and updates these distances as new, shorter paths are
discovered.

3 Iterative Process
The algorithm iteratively selects the unvisited node with the
shortest known distance from the start node and updates the
distances to its neighbors.
Pseudocode for
Dijkstra's Algorithm
Initialize Select Minimum
Set the distance to the start Choose the unvisited node
node as 0 and all other nodes with the smallest known
as infinity. distance from the start node.

Update Distances Mark as Visited


For each unvisited neighbor Mark the selected node as
of the selected node, update visited to avoid revisiting it in
its distance if a shorter path the future.
is found.
Time Complexity
Analysis Priority Queue
By using a priority queue, the time
complexity can be reduced to O(E
log V), where E is the number of
Naive edges in the graph.
Implementation
The basic implementation of
Heap-Based
Dijkstra's algorithm has a time
complexity of O(V^2), where V is the
Approach
Implementing Dijkstra's algorithm
number of vertices in the graph.
with a binary heap can further
improve the time complexity to O(E
log V).
Implementation
Considerations
1 Data Structures 2 Edge Weights
The choice of data Dijkstra's algorithm
structures, such as priority assumes non-negative
queues or heaps, can edge weights, which can
significantly impact the be a limitation in certain
algorithm's performance. applications.

3 Memory Usage
The algorithm requires storing the distance and previous node
information for each vertex, which can consume significant
memory for large graphs.
Weighted Graphs and Edge
Weights

Edge Weights Vertex Cumulative


Dijkstra's algorithm operates on Connectivity
The algorithm explores the Distance
It calculates the total distance from
weighted graphs, where each edge connections between vertices, using the start node to each reachable
has an associated weight or cost. the edge weights to determine the vertex, finding the path with the
shortest path. minimum cost.
Prioritizing Vertices with
a Priority Queue
Vertex Selection
Dijkstra's algorithm uses a priority queue to efficiently select
the unvisited vertex with the smallest known distance from
the start.

Distance Updates
When a shorter path is found to a vertex, the priority queue is
updated to maintain the correct ordering of vertices.

Time Complexity
The use of a priority queue reduces the time complexity of
Dijkstra's algorithm to O(E log V).
Handling Negative Edge
Weights
Limitation Alternative Workarounds
Algorithms
Dijkstra's algorithm assumes that all For graphs with negative edge In some cases, the problem can be
edge weights are non-negative. It weights, alternative algorithms such transformed to fit the requirements
cannot handle graphs with negative as the Bellman-Ford algorithm or the of Dijkstra's algorithm, such as by
edge weights, as it may not find the A* algorithm can be used to find the adding a constant to all edge
correct shortest path. shortest paths. weights to make them non-negative.
Applications of Dijkstra's
Algorithm
Routing and Network
Navigation Optimization
It is used in network routing
Dijkstra's algorithm is widely
protocols to determine the
used in GPS and mapping
optimal path for data
applications to find the shortest
transmission across a network.
path between two locations.

Social Network
Pathfinding and
Analysis
AI
Dijkstra's algorithm is a The algorithm can be used to
fundamental technique in game analyze and understand the
development and robotics for relationships and influence
solving pathfinding problems. within social networks.
Conclusion and Key
Takeaways Shortest Path
1
Dijkstra's algorithm is a powerful tool for finding the
shortest path between two nodes in a weighted graph.

2 Efficiency and
Optimizations
The algorithm's time complexity can be improved by using
Limitations and 3 efficient data structures, such as priority queues or heaps.
Dijkstra's algorithm is limited to graphs Alternatives
with non-negative
edge weights, and alternative algorithms may be required
for graphs with negative weights.

You might also like