Algo Assignment
Algo Assignment
Algorithm
Hasan Farooq
23-03-0016
where d(u) is the shortest known distance to vertex u, w(u, v) is the edge weight, and
d(v) is the current shortest distance to vertex v.
Differences from Dijkstra:
• Approach: Bellman-Ford relaxes all edges iteratively, while Dijkstra uses a greedy
priority queue.
1
• Shortest paths may require multiple edges to traverse.
• Each iteration accounts for paths with one more edge than the previous iteration.
• Shortest path calculations lose meaning because distances can decrease indefinitely.
Key Differences:
• Efficiency: Bellman-Ford has O(V ×E) complexity; Dijkstra is faster with O((V +
E) log V ) when using a heap.
2
Problem 6: Bellman-Ford on a Small Graph
Graph Details:
• A → B (4)
• A → C (5)
• B → C (-3)
• C → D (2)
• B → D (4)
Step-by-Step Execution:
1. Initialization:
2. Iteration 1:
• B → C (-2), C → D (3)
• D → E (-1), B → E (5)
Relaxation is performed for V − 1 iterations, followed by a check for further updates
in the V -th iteration to detect cycles.
3
Problem 9: Energy-Efficient Wireless Networks
Representation: