| Component | Role |
|---|---|
| Adjacency List (Graph) | Represents intersections (nodes) and roads (edges with weights). |
| Priority Queue (Min-Heap) | Efficiently selects the closest node during pathfinding. |
| Hash Map – Distance Table | Tracks the shortest distance from the source node. |
| Hash Map – Parent Table | Records node relationships for path reconstruction. |
| Dijkstra’s Algorithm | Computes the guaranteed shortest path when all weights are non-negative. |
-
Core Logic:
- Implement Dijkstra’s Algorithm using an adjacency list.
-
Data Representation:
- Store map data in a JSON file. Example:
{ "A": [["B", 4], ["C", 2]], "B": [["A", 4], ["D", 5]], "C": [["A", 2], ["D", 8]], "D": [["B", 5], ["C", 8], ["E", 2]] }
- Store map data in a JSON file. Example:
-
Backend (Flask):
- Handles algorithm execution, route calculations, and updates.
-
Frontend (HTML + JS):
- Allows users to input source/destination.
- Displays the computed path and distance visually.
User selects a source and destination via the web interface.
Backend loads the road network from a JSON adjacency list.
Flask backend runs Dijkstra’s Algorithm:
- Initializes all node distances to infinity (∞) except the source = 0.
- Uses a priority queue to explore nearest unvisited nodes.
- Updates neighbor distances if a shorter path is found.
- Records parent nodes for route reconstruction.
Returns:
- Shortest path
- Total distance
- Estimated time
- Complexity details
JavaScript frontend displays the path on a simple map.
When traffic data or edge weights change, the system recalculates and re-renders the optimized route.
Dijkstra’s Algorithm (Min-Heap Implementation)
- Set initial distance of all nodes to infinity except the source = 0.
- Use a min-heap to repeatedly extract the node with the smallest tentative distance.
- For each neighbor, calculate alternative distances.
- Update distance and parent if shorter.
- Continue until all nodes are processed or destination is reached.
Time Complexity: O(E log V)
Space Complexity: O(V + E)
| Layer | Technology |
|---|---|
| Frontend | HTML, CSS, JavaScript |
| Backend | Python (Flask) |
| Algorithm | Dijkstra’s Algorithm |
| Data Storage | JSON Adjacency List |
| Visualization | JavaScript Map Display |