Suppose you are given a connected undirected weighted graph G with a particular vertex s designated as the source. It is also given to you that weight of every edge in this graph is equal to 1 or 2. You need to find the shortest path from source s to every other vertex in the graph. This could be done using Dijkstra’s algorithm but you are told that you must solve this problem using a breadth-first search strategy. Design a linear time algorithm (Θ(|V | + |E|)) that will solve your problem. Show that running time of your modifications is O(|V | + |E|). Detailed pseudocode is required. Hint: You may modify the input graph (as long as you still get the correct shortest path distances)
Suppose you are given a connected undirected weighted graph G with a particular vertex s designated as the source. It is also given to you that weight of every edge in this graph is equal to 1 or 2. You need to find the shortest path from source s to every other vertex in the graph. This could be done using Dijkstra’s
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images