Professional Documents
Culture Documents
Jannatul Hafsa Mim - 201!16!500
Jannatul Hafsa Mim - 201!16!500
ID:201-16-500
Department of CIS
Subject: Algorithm
Spring 2021
FINAL ASSINGMENT
Theory Part
Task 1:
(a) Design an algorithm to find the best route for the problem above. Your algorithm
Should not manually check every edge in the graph, rather it should opt for a
Greedy approach.
(b) If you were to visit all the intersections in the graph by crossing the least amount
of traffic instead of finding the shortest route, which algorithm could you use?
If I were to visit all the intersections in the graph by crossing the least amount of traffic
instead of finding the shortest route, I would use Prim’s algorithm.
There are two algorithm for crossing the graph with the least amount of traffic. One is
edge approach which is Kruskal’s and the other one is vertex approach that is Prim’s
From the graph we can see that there is 14 vertices and 18 edges.
Prim’s algorithm travels by adding the cost of the lowest vertex to the existing vertex. On
the other hand kruskal’s algorithm travels by adding the lowest edge to the existing edge.
So it would be difficult for kruskal’s algorithm to travel so many edges because it
approaches through edge. Therefore in a comparative way it will take more time than
prim’s. for that reason prim’s algorithm will work better because prim’s is faster.
Additionally prim’s will work nicely because our graph has many edges and kruskal’s
will work faster in those graph which has less edges.
Task 2 (Simulation):
(a) Simulate the algorithm you have written for the given test case to find the
Shortest route from Motijheel to Mogbazar.
Lab Part
Task 1:
Write the Java Code for the problem based on your algorithm.
Task 2:
(a) BFS is an algorithm that also gives the shortest path between source and
destination. Run BFS on the given graph and show the output.
Task 3:
If you were to change some of the edge costs in your given graph to negative values,
the greedy approach to the shortest path algorithm would not work. Why would that be?
Explain briefly.