CS 411 Fall 2025 > Outline for October 31, 2025
CS 411 Fall 2025
Outline
for October 31, 2025
Outline
Greedy Techniques [L Ch 9 intro]
- Idea: be short-sighted. At each step, make what seems to be the best choice right now.
- Greedy techniques, at each step, make a choice that is:
- Feasible (legal, within constraints of problem).
- Locally optimal.
- Irrevocable.
- Being greedy usually gives incorrect results.
- Example of maximum weight independent set in vertex-weighted graph.
- We will discuss algorithms in which working greedily always gives a correct result. Greedy techniques are also usually very fast.
Spanning Trees I: Prim’s Algorithm [L 9.1]
- Spanning Trees
- Connected graph
- Tree
- Spanning tree
- (Edge-)weighted graph
- Minimum spanning tree
- Minimum Spanning Tree Problem
- Two greedy algorithmic ideas
- Idea #1 (Prim’s Algorithm—today). Choose a vertex, and count it as reachable. Then repeat: add to the spanning tree the least-weight edge from a reachable vertex to an unreachable vertex—which then becomes reachable.
- Idea #2 (Kruskal’s Algorithm—next time). Repeat: Add to a collection of edges the least-weight edge between two vertices that we cannot currently travel between (that is, the least-weight edge that, when added to the collection, will not form a cycle).
- Prim’s Algorithm: Correctness
- Prim’s Algorithm: Implementation
- For efficiency, use Priority Queue to select least-weight edge.
- Prim’s Algorithm: Efficiency