minimum spanning trees n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Minimum Spanning Trees PowerPoint Presentation
Download Presentation
Minimum Spanning Trees

Loading in 2 Seconds...

play fullscreen
1 / 17

Minimum Spanning Trees - PowerPoint PPT Presentation


  • 107 Views
  • Uploaded on

Minimum Spanning Trees. Definition Algorithms Prim Kruskal Proofs of correctness. Problem 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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Minimum Spanning Trees' - afram


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
minimum spanning trees
Minimum Spanning Trees
  • Definition
  • Algorithms
    • Prim
    • Kruskal
  • Proofs of correctness
problem definition
Problem 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 formed
kruskal s algorithm
Kruskal’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?
disjoint set data structure

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

Disjoint-set Data Structure
  • 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) = G
cycle detection

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

Cycle Detection
  • 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.
update disjoint set data structure
Update Disjoint-set Data Structure
  • 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) = G

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

time for disjoint set data structure operations
Time 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 a(V) time where a is a very slow growing function
    • O(E a(V)) time overall which is essentially O(E) for all practical purposes
overall running time
Overall 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 a(V) time where a is a very slow growing function
    • O(E a(V)) time overall for cycle detection
  • O(E log E) time for sorting edges by weight dominates
prim s algorithm
Prim’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
priority queue

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

Priority Queue
  • 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: 6
updating priority queue

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

Updating Priority Queue
  • 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: 6
updating priority queue1
Updating Priority Queue
  • 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: 6

1

4

2

A

B

C

D

5

6

3

10

2

5

E

F

G

running time analysis
Running 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 time
proofs of correctness kruskal
Proofs 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 tree
proofs of correctness kruskal1
Proofs 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 kruskal2
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
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 argument