Question
(a) Why does the greedy algorithm work for the spanning tree problem?(b) Show by example that the greedy algorithm could fail to find the shortest path from $s$ to $t$, by starting with the shortest edge.
Step 1
This is based on the principle of "greediness", which means that the algorithm makes the locally optimal choice at each stage with the hope that these local choices will lead to a global optimum. In the case of the spanning tree problem, the greedy algorithm Show more…
Show all steps
Your feedback will help us improve your experience
Victor Salazar and 54 other educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Suppose we run Dijkstra's algorithm from a start node s in a weighted undirected graph. The distance to each reachable node t is given by distTo.get(t). What do we know about the shortest path between any two other nodes u and v—assuming neither is the start node? Explain your reasoning for all 4 answer choices. (It is sufficient to give a counterexample for incorrect answers.) There can only exist a single shortest path from u to v. A shortest path from u to v must include one or more edges in the shortest paths tree from s. If the shortest paths tree reaches u and v, then u and v are connected. The distance of a shortest path from u to v cannot be greater than distTo.get(u) + distTo.get(v).
Explain how to find a path with the least number of edges between two vertices in an undirected graph by considering it as a shortest path problem in a weighted graph.
Graphs
Shortest-Path Problems
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD