Arun Exp-8
Arun Exp-8
Experiment-8
Student Name: Arun UID:22BET10320
Branch: IT Section/Group:22BET_IoT_703-B
Semester: 5th Date of Performance: /10/2024
Subject Name: DAA Lab Subject Code: 22CHS-311
1. Aim: Develop a program and analyze complexity to find shortest paths in a graph with
positive edge weights using Dijkstra’s algorithm.
2. Objective: To implement and analyze the efficiency of Dijkstra’s algorithm for finding
the shortest paths in a graph with positive edge weights. The goal is to evaluate the
algorithm's time complexity based on the data structure used for the priority queue (e.g.,
binary heap or Fibonacci heap).
3. Implementation/Code:
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
/**
* Dijkstra's algorithm to find the shortest paths from a source node.
*
* @param source The source node.
* @param graph The graph represented as an adjacency list.
* @param V The number of vertices in the graph.
*
* @return A vector of shortest distances from the source node to all other nodes.
*/
vector<int> dijkstra(int source, const vector<vector<PII>>& graph, int V) {
// Create a min-heap priority queue to store vertices to be processed
priority_queue<PII, vector<PII>, greater<PII>> pq;
int main() {
int V, E; // Number of vertices and edges
cout << "Enter the number of vertices: ";
cin >> V;
cout << "Enter the number of edges: ";
cin >> E;
return 0;
}
4. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Time Complexity:
• Using Binary Heap: O((V + E) log V), where V is the number of vertices and E is the
number of edges.
• Using Fibonacci Heap: O(E + V log V).
• Space Complexity: The overall space complexity of Dijkstra’s algorithm is O(V + E),
where V is the number of vertices and E is the number of edges.
6. Learning Outcomes:
• Understanding of Dijkstra's Algorithm: You will learn how to implement and apply
Dijkstra’s algorithm to find the shortest paths in graphs with positive edge weights,
utilizing a priority queue for efficiency.
• Time and Space Complexity Analysis: You will gain insights into analyzing the time
complexity (O((V + E) log V) using a binary heap) and space complexity (O(V + E))
of the algorithm.
• Graph Representation: You will understand how to represent graphs efficiently using
adjacency lists and handle shortest path problems with real-world applications.