Final Exam
Final Exam
: 2nd BSCS
Djikstra used this property in the opposite direction i.e we overestimate the distance of
each vertex from the starting vertex. Then we visit each node and its neighbours to find
the shortest subpath to those neighbours.
The algorithm uses a greedy approach in the sense that we find the next best solution
hoping that the end result is the best solution for the whole problem.
Output: 0 4 12 19 21 11 9 8 14
Explanation: The distance from 0 to 1 = 4.
The minimum distance from 0 to 2 = 12. 0->1->2
The minimum distance from 0 to 3 = 19. 0->1->2->3
The minimum distance from 0 to 4 = 21. 0->7->6->5->4
The minimum distance from 0 to 5 = 11. 0->7->6->5
The minimum distance from 0 to 6 = 9. 0->7->6
The minimum distance from 0 to 7 = 8. 0->7
The minimum distance from 0 to 8 = 14. 0->1->2->8
4. Applications of Dijkstra’s Algorithm.
Answer:
Dijkstra’s algorithm is widely used in the routing protocols required by the routers to
update their forwarding table. The algorithm provides the shortest cost path from the
source router to other routers in the network.