DOC PREVIEW
MSU CSE 830 - Lecture14

This preview shows page 1-2-3-4-5-6 out of 17 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Minimum Spanning TreesProblem DefinitionKruskal’s algorithmDisjoint-set Data StructureCycle DetectionUpdate Disjoint-set Data StructureTime for Disjoint-set Data Structure OperationsOverall Running TimePrim’s algorithmPriority QueueUpdating Priority QueueSlide 12Running time AnalysisProofs of Correctness (Kruskal)Slide 15Slide 16Proofs of Correctness (Prim)Minimum Spanning Trees•Definition•Algorithms–Prim–Kruskal•Proofs of correctnessProblem Definition•Input–Weighted, connected undirected graph G=(V,E)•Weight (length) function w on each edge e in E•Task–Compute a spanning tree of G of minimum total weight•Spanning tree–If there are n nodes in G, a spanning tree consists of n-1 edges such that no cycles are formedKruskal’s algorithm•Greedy approach to edge selection–Select the minimum weight edge that does not form a cycle–Implementation•Sort edges by increasing lengths–Alternatively use heap to store edges–Either way: O(E log E) time•Include minimum weight edge if it does not form a cycle.•How do we test if edge forms a cycle?•Use disjoint-set data structure (Chapter 21)–Each vertex belongs to a set containing the vertices in its current tree (initially only itself)–Find-set(A) = Find-set(B) = Find-set(E) = A–Find-set(C) = Find-set(D) = C–Find-set(F) = F–Find-set(G) = GDisjoint-set Data StructureA B CDE F G1223455610•Take minimum weight edge and test both endpoints to see if they are in same set•Min weight edge: (A,E). Same Set. Cycle.•Min weight edge: (B,C): Different Sets. No cycle.Cycle DetectionA B CDE F G1223455610•Merge sets corresponding to node B and node C.–We need the result to now be:–Find-set(A) = Find-set(B) = Find-set(E) = Find-set(C) = Find-set(D) = A (or C)–Find-set(F) = F–Find-set(G) = GUpdate Disjoint-set Data StructureA B CDE F G1223455610Time for Disjoint-set Data Structure Operations•Initialization:–Makeset(v) for all vertices v: O(V) time•Merges and Find-set Operations–O(V) merges and O(E) Find-sets–Each can be implemented in amortized (V) time where  is a very slow growing function–O(E (V)) time overall which is essentially O(E) for all practical purposesOverall Running Time•Initialization:–Makeset(v) for all vertices v: O(V) time•Merges and Find-set Operations–O(E) of them–Each can be implemented in amortized (V) time where  is a very slow growing function–O(E (V)) time overall for cycle detection•O(E log E) time for sorting edges by weight dominatesPrim’s algorithm•Different greedy approach to edge selection–Initialize connected component N to be any node v–Select the minimum weight edge connecting N to V-N–Implementation•Maintain a priority queue for the nodes in V-N based on how close they are to any node in N•When a new node v is added to N, we need to update the weight of the neighbors of v in V-N•Maintain priority queue of nodes in V-N•If we started with node D, N is now {C,D}•Priority Queue values of other nodes:–A, E, F: infinity–B: 4–G: 6Priority QueueA B CDE F G1223455610•Node B is added to N; edge (B,C) is added to T•Need to update priority queue values of A, E, F–Decrease-key operation•Priority Queue values of other nodes:–A: 1–E: 2–F: 5–G: 6Updating Priority QueueA B CDE F G1223455610•Node A is added to N; edge (A,B) is added to T•Need to update priority queue values of E–Decrease-key operation•Priority Queue values of other nodes:–E: 2 (unchanged because 2 is smaller than 3)–F: 5–G: 6Updating Priority QueueA B CDE F G1223455610Running time Analysis•Assume binary heap implementation•Build initial heap takes O(v) time•V extract-min operations for O(V log V) time•For each edge, potentially 1 decrease-key operation, so O(E log V) time•Overall: O(E log V) time which is asymptotically equivalent to our implementation of Kruskal’s algorithm•Use of fibonacci heap can improve running time to O(E + V log V) time–Decrease-key drops to O(1) amortized timeProofs of Correctness (Kruskal)•Let T’ be a minimum spanning tree for G•Let T be the tree formed by Kruskal’s algorithm that utilizes edges in T’ whenever a tie needs to be broken•Assumption: T has more weight than T’–Otherwise Kruskal’s algorithm has produced an optimal treeProofs of Correctness (Kruskal)•Let e be the smallest weight edge in T that is not in T’•Add e to T’ and consider the cycle Y that is formed•There must be some edge e’ on Y that has weight greater than e. •Explain why?–What do we know about T and T’ up to this point?Proofs of Correctness (Kruskal)•Replace e’ by e in T’•We have a new spanning tree T’’ such that the weight of T’’ is smaller than the weight of T’•This contradicts the fact that T’ was optimal.•This implies no such edge e can be found, and thus T must be optimal.Proofs of Correctness (Prim)•Let T’ be a minimum spanning tree for G•Let T be the tree formed by Prim’s algorithm that utilizes edges in T’ whenever a tie needs to be broken•Assumption: T has more weight than T’–Otherwise Prim’s algorithm has produced an optimal tree•Let e be the first edge added to T that is not in T’•Finish this


View Full Document

MSU CSE 830 - Lecture14

Download Lecture14
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture14 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture14 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?