Lecture20-mst-prims

This preview shows pages 1–20. Sign up to view the full content.

CS 312: Algorithm Analysis Lecture #20: Minimal Spanning Trees; Prim’s Algorithm This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Slides by: Eric Ringger, with figures from Dasgupta et al.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Announcements § Homework #13 due now § Project #4 - “Intelligent scissors” § Early: Monday § Due: Wednesday § Start early, finish early! § Clarification on SimpleScissors: When two or more directions have equal weight, ties should be broken as follows: Prefer pixels in clockwise order, starting with the pixel to the north (upwards in the image; lower y-coordinate).
Objectives § More Greedy Algorithms § Analysis of Kruskal’s Algorithm § Requires Implementation of Disjoint Sets § Prim’s Algorithm for MST § Head-to-head analysis of Prim’s and Kruskal’s

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Greedy Algorithms § Which greedy algorithms have you seen so far? § Distinguish between “thoughtful” and “not- so-thoughtful” greedy algorithms § E.g., Intelligent scissors vs. Simple scissors
Kruskal’s Algorithm Objective: Identify: - Important operations - Elements of a Greedy algorithm break if size(X) == |V|-1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Data Structure For Disjoint Sets § makeset(x): create a singleton set containing just x § find(x): find the set to which x belongs § union(x, y): merge the sets containing x and y How would you implement a data structure providing these methods?
Disjoint Sets as Shallow, Directed Trees {A,C,D,F,G,H} {B,E}

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Disjoint Set Operations
Disjoint Set Operations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Disjoint Set Operations Let’s try an example …
Example Disjoint Set Ops

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example (cont.)
Example (cont.)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Claim § For a given set S, no tree representing disjoint sets in this manner is every deeper than log |S| § If you have a counter-example, I want to see it!
Analyze: Disjoint Set Operations

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Lemma Lemma : O(log|V|)=O(log|E|)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Kruskal’s Algorithm break if size(X) == |V|-1
§ Idea: § Intermediate set of edges X always forms a sub-tree § S is chosen to be the set of X’s vertices. § On each iteration, X grows by one edge

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.