23   


                         
minimum‐spanning‐tree Problem 
          2009/06/08 
           id:tksmd
•                   (id:tksmd) 
     –                                                        
     –  i    (isenshi.com) ...
•               
     –              (                    ) 
     –                                             
     –   ...
•          (Spanning Tree) 
     – 
                               
•                      (Minimum Spanning Tree) 
     – 
                                                       
     –    ...
•                                                                    


                          8
                 7
   ...
•                                                                   

                           5
               7
      ...
•  STP (Spanning Tree Protocol) 
  –  LAN                   (=      )
                      
  –               

  – 
    ...
•              G = (V, E) (u,v) ∈ E
•              w(T) =     ∑ w(u,v) (T ⊂ E)
                        (u,v )∈T

•        ...
•                  
     – 
               
     – 
           
     –                 
GENERIC - MST(G,w)
1 A←∅
2 while A ≠ MST
3 do find safe edge (u,v) for A
4     A ← A ∪ {(u,v)}
5 return A
T = {(a,b),(b,c),(c,d),(c, f ),(c,i),(d,e),( f ,g),(g,h)}
                      8
                  7
             b
     ...
•          

               
     A                




                           
                               
      ...
•                                               
      –           23.1            
      –  A                           G...
•                                            (        ) 
     –   23.2 
     –  GA = (V,A)                                ...
•          
     – 
                   
     – 

               
•                          
     –                         
     –                 


•                          
     –  ...
•                  
     –                                             
     –                                            ...
8
              7
           b
              c
                 d
     4
                                                 ...
8
          7
           b
              c
         d
     4
                                      9
        3.           ...
•                
     – 
                                             


•                     
     –                   ...
•               
     –                O(V)
     –             O(E lg E)
     –               
          •  O((V+E)α(V)) (...
•                     
     – 
                                              
     MST − PRIM(G,w,r)
      1 for each u ∈ ...
8
              7
           b
              c
                 d
     4
                                                 ...
8
          7
           b
              c
         d
     4
                                      9
        3.           ...
•               
     –                                
     –                                    


•                    ...
•             
     –         O(V)
     –     EXTRACT‐MIN        O(V lg V)
     –                O(E lg V)
     –        O...
•                                 
     –         O(V)
     –     EXTRACT‐MIN       O(V lg V)
     –                O(E)
 ...
8
                7
           b
                    c
             d
     4
                                             ...
•                     
     –                               
     –  O(E lg V)



•  Reverse‐DeleCon   
     –            ...
•                              
     –                                             
     –                     
          ...
Upcoming SlideShare
Loading in …5
×

Algo 23 MSTP

1,900 views

Published on

アルゴリズムイントロダクション 23 章輪講資料

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,900
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • BPDU<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • 逆に全ての辺が異なる重みをもつ場合には唯一に定まる<number>
  • Algo 23 MSTP

    1. 1.  23      minimum‐spanning‐tree Problem  2009/06/08  id:tksmd
    2. 2. •   (id:tksmd)  –    –  i (isenshi.com)    –  Seasar FoundaCon    –    •  Related Works  –  Choistudy (hHp://www.choistudy.jp/)  –  Tuigwaa/escafeWeb (hHp://www.escafe.org/)  –  Cubby (hHp://cubby.seasar.org/)  –   on MySpace (hHp://www.myspace.com/u10asia90) 
    3. 3. •    –   ( )  –    –    •    •       (Minimum Spanning Tree Problem)  
    4. 4. •   (Spanning Tree)  –   
    5. 5. •   (Minimum Spanning Tree)  –    –    8 7 b c d 4 9 2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f w(T) = ∑ w(u,v) =37 (u,v )∈T
    6. 6. •    8 7 b c d 4 9 2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f w(T) = ∑ w(u,v) =37 (u,v )∈T
    7. 7. •    5 7 b c d 3 9 6 a 11 i 4 14 e 12 13 8 10 h 1 g 2 f w(T) = ∑ w(u,v) =37 (u,v )∈T
    8. 8. •  STP (Spanning Tree Protocol)  –  LAN (= )   –    –   
    9. 9. •    G = (V, E) (u,v) ∈ E •    w(T) = ∑ w(u,v) (T ⊂ E) (u,v )∈T •    A⊆T € €
    10. 10. •    –    –    –   
    11. 11. GENERIC - MST(G,w) 1 A←∅ 2 while A ≠ MST 3 do find safe edge (u,v) for A 4 A ← A ∪ {(u,v)} 5 return A
    12. 12. T = {(a,b),(b,c),(c,d),(c, f ),(c,i),(d,e),( f ,g),(g,h)} 8 7 b c d 4 9 A = {(c,i),( f ,g),(g,h)} 2 a 11 i 4 14 e 7 6 8 10 h g f 1 2 € 8 7 A = {(c,i),(c, f ),( f ,g),(g,h)} b c d 4 9 2 a 11 i 4 14 e 7 6 8 10 € h 1 g 2 f
    13. 13. •      A     
    14. 14. •    –   23.1    –  A  G  (S,V-S)    –  (S,V-S)  (u,v)    A = {(c,i),( f ,g),(g,h)} 8 7 b c d 4 9 2 a 11 i 4 14 e S € 7 6 8 10 V-S h g f 1 2
    15. 15. •   ( )  –   23.2  –  GA = (V,A)  C = (VC,EC)   –  C  GA  (u,v) (u,v)  A    A = {(c,i),( f ,g),(g,h)} 8 7 b c d 4 9 2 a 11 i 4 14 e € 7 6 8 10 h 1 g 2 f
    16. 16. •    –    –   
    17. 17. •    –    –    •    –    –    –   
    18. 18. •    –    –    MST − KRUSKAL(G,w) 1A←∅ 2 for each v ∈ V[G] 3 do MAKE - SET(v) 4 sort E with weight w ascending order 5 for each (u,v) ∈ E (with sorting order) 6 do if FIND - SET(u) ≠ FIND - SET(v) 7 then A ← A ∪ {(u,v)} 8 UNION(u,v) 9 return A
    19. 19. 8 7 b c d 4 1.  9 2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f 8 7 b c d 4 9 2.  2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f
    20. 20. 8 7 b c d 4 9 3.    2        a 11 i 14 e      4 7 6 8 10 h 1 g 2 f 8 7 b c d 4 9 2 4.    a 11 i 4 14 e      7 6 8 10 h 1 g 2 f
    21. 21. •    –    •    –   (disjoint‐set forest)    •  m   MAKE‐SET  n   MAKE‐SET/UNION/FIND‐ SET  O(mα(n))
    22. 22. •    –  O(V) –  O(E lg E) –     •  O((V+E)α(V)) (|E|>=|V|-1) •  = O(Eα(V)) (α(|V|)=O(lg V)=O(lg E)) •  = O(E lg E) (|E|<|V|2) •  = O(E lg V)
    23. 23. •    –    MST − PRIM(G,w,r) 1 for each u ∈ V [G] 2 do key[u] ← ∞ 3 π [u] ← NIL 4 key[r] = 0 A = {(v, π (v)) : v ∈ V − {r}} 5 Q ← V[G] 6 while Q ≠ ∅ 7 do u ← EXTRACT - MIN(Q) 8 for each v ∈ Adj[u] € 9 do if v ∈ Q and w(u,v) < key[v] 10 then π [v] ← u 11 key[v] ← w(u,v)
    24. 24. 8 7 b c d 4 1.    9 2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f 8 7 b c d 4 9 2.  2 a 11 i 4 14 e 7 6 8 10 h 1 g 2 f
    25. 25. 8 7 b c d 4 9 3.    2      a 11 i 4 14 e 7 6 8 10 h 1 g 2 f 8 7 b c d 4 9 2 4.    a 11 i 4 14 e      7 6 8 10 h 1 g 2 f
    26. 26. •    –    –    •    –    •  BUILD‐MIN‐HEAP O(n) •  EXTRACT‐MIN O(lg n) •  DECREASE‐KEY O(lg n)
    27. 27. •    –  O(V) –   EXTRACT‐MIN  O(V lg V) –  O(E lg V) –  O(V lg V + E lg V)
    28. 28. •    –  O(V) –   EXTRACT‐MIN  O(V lg V) –  O(E) –  O(V lg V + E)
    29. 29. 8 7 b c d 4 9 2 1.    a 11 i 14 e   4 7 6 8 10 h 1 g 2 f 8 ab cdei 2.         MST‐PRIM  8 4 fgh
    30. 30. •    –    –  O(E lg V) •  Reverse‐DeleCon    –    –    –  O(E lg E (lg lg E)3)
    31. 31. •    –    –    •   MST    •  O(E lg V) –    •   MST    •  O(E lg V) •    O(E+V lg V)

    ×