DAA Project Report
DAA Project Report
We are tasked with finding the shortest travel time between all pairs of cities in a large metropolitan area
or an entire country. Each city is a node in a graph, and the edges between them represent roads or air
routes, with weights indicating the time or distance required to travel between two cities.
Graph Representation: The transportation network can be represented as a weighted graph, where each
city is a node and each road or route between cities is an edge with a weight (distance or travel time).
Adjacency Matrix: The graph will be represented as an adjacency matrix dist[][], where dist[i][j]
contains the travel time (or distance) between city i and city j. If no direct road exists between two cities,
the matrix entry is infinity (∞), except when i = j (i.e., the diagonal elements), which should be 0 (since
the shortest distance from a city to itself is zero).
The transportation network problem is crucial for improving efficiency in cities and reducing travel time
for commuters. By finding the shortest paths between all pairs of cities, the algorithm can help design
better routes for public transportation, plan road expansions, or optimize flight schedules. Moreover, it
has wide applicability in logistics, delivery services, and emergency response systems where quick
decision-making based on shortest routes is essential.
1. Let dist[][] be the adjacency matrix of the graph, initialized with the weights of the edges.
For each i and j, dist[i][j] = weight of edge (i, j), or ∞ if there is no edge.
For each i, dist[i][i] = 0 (shortest path from a node to itself is zero).
2. For each intermediate node k from 1 to n:
For each node i from 1 to n:
For each node j from 1 to n:
If dist[i][j] > dist[i][k] + dist[k][j]:
dist[i][j] = dist[i][k] + dist[k][j]
3. The matrix dist[][] now contains the shortest distances between all pairs of nodes.
Data Structures
The main data structure used in the Floyd-Warshall algorithm is the adjacency matrix, a 2D array or
matrix that represents the graph. The dist[i][j] holds the shortest distance between node i and node j.
Time Complexity: The Floyd-Warshall algorithm has three nested loops, each running from 1 to
n, where n is the number of nodes (cities). Therefore, the time complexity is O(n^3).
Space Complexity: The algorithm uses an adjacency matrix dist[][], which takes O(n^2)
space, where n is the number of nodes.
Expected Outcome
The expected outcome of applying the Floyd-Warshall algorithm to the transportation network is a matrix
of shortest travel times (or distances) between every pair of cities. This matrix will allow efficient
querying and route optimization. In addition, the algorithm provides a global view of the transportation
network's efficiency, revealing potential areas for improvement, such as reducing congestion by
optimizing existing routes or expanding the network.