disjoint sets part 2
play

Disjoint Sets - Part 2 Todays announcements: PA3 out, due 29 March - PowerPoint PPT Presentation

Disjoint Sets - Part 2 Todays announcements: PA3 out, due 29 March 11:59p Todays Plan Disjoint Sets Representing S = {{ 0 , 1 , 4 } , { 2 , 7 } , { 3 , 5 , 6 }} : 0 1 2 3 4 5 6 7 0 0 2 3 0 3 3 2 1 / 8 Disjoint Sets


  1. Disjoint Sets - Part 2 Today’s announcements: ◮ PA3 out, due 29 March 11:59p Today’s Plan ◮ Disjoint Sets Representing S = {{ 0 , 1 , 4 } , { 2 , 7 } , { 3 , 5 , 6 }} : 0 1 2 3 4 5 6 7 0 0 2 3 0 3 3 2 1 / 8

  2. Disjoint Sets using UpTrees 0 2 3 8 S = {{ 0 , 1 , 4 } , { 2 , 7 } , { 3 , 5 , 6 } , { 8 }} 1 7 5 6 4 Find runtime depends on? int DS::Find( int k ) { if( parent[k] == k ) return k; else return Find( parent[k] ); } void Link(int root1, int root2) { parent[root__] = root__; } void DS::Union(int k1, int k2) { Link(Find(k1),Find(k2)); } 2 / 8

  3. Smart Union 0 3 1 5 6 8 4 Union by height Choose root to minimize height. Union by size Choose root to minimize total depth. Following either scheme guarantees tree with n nodes has height: 3 / 8

  4. Smart Union Code void LinkBySize(int root1, int root2) { if (size[root1] >= size[root2]) { parent[root2] = root1; size[root1] += size[root2]; } else { parent[root1] = root2; size[root2] += size[root1]; } } 0 3 1 5 6 8 4 4 / 8

  5. Path Compression during Find int DS::Find( int k ) { if( parent[k] == k ) return k; else { parent[k] = Find( parent[k] ); return parent[k]; } } 3 Find(2) 3 5 6 8 1 4 2 5 6 8 7 1 4 7 2 5 / 8

  6. Running time with smart union and path compression Iterated logarithm lg ∗ n � 0 if n ≤ 1 lg ∗ n = 1 + lg ∗ (lg n ) otherwise In other words, lg ∗ n is the number of times we can take lg iteratively until the result is at most 1. Example: lg ∗ (2 65536 ) = The number of atoms in the universe is estimated to be at most 2 273 . Theorem If m operations, either Union or Find, are applied to n elements, the total run time is O ( m lg ∗ n ) . Actually, O ( m α ( m , n )) is a better bound, where α ( m , n ) is the inverse Ackermann function, which grows verrrry slowly. 6 / 8

  7. ☜ ☜ ☜ ☜ ☜ ☜ ◀ Graphs bipartite ∩ unicyclic claw-free cactus 2-con K2-free SC 2-tree probe nected interval caterpillar ▼ partial grid ▼ 2-sub- bipartite probe cubic@ outer- Apollonian division@ ▶ interval planar network 2-tree ∩ tree binary planar 4-regu- bipartite tree deg ≤ 3 lar@ ▼ tolerance ∩ tree tree 2term planar … hamilt. Halin median@ E-free@ deg ≤ 4 ▽ C 4 -C 6 - C 8 -K 1,4 - series- odd cycle- parallel Laman free chordal@ 2-outer- planar bipartite@ domination perfect@ partial C 4 - 3-tree@ triangle- H n,q -grid unit… free k-outer- planar 2-con nected polyhedral lin. convex maximal C 4 -C 5 -K 4 - tr.grid planar diamond- graph homoth. locally bar free@ triangle strict triangle- odd-hole connected visibility B 1 -VPG free@ contact free@ ▼ contact solid … triang. gid grid graph deg ≤ 3 ▼ planar solid Planar Graphs relative … 2-strongly neighbor- regular@ hood grid graph strongly Gabriel ☜ graph class regular@ Urquhart ☜ class of bounded degree graphs label abbreviation class A@ class A ∩ planar graphs partial ☜ class of grid-like structured graphs grid class A ▼ class A ∩ unique ancestor ☜ class of trees class A ∩ left ancestor B class A ◀ B class A includes class B class A ▶ class A ∩ right ancestor A A class A… class A + name of the unique ancestor by Tamara Mchedlidze 7 / 8

  8. Graphs 0 0 6 1 5 1 5 2 4 2 4 3 3 7406 divisible by 6 (or 7)? 1. Start at vertex 0 and leading digit. 2. At digit d , follow d black edges and then one red edge, and move to next digit. 3. Divisible by 6 (or 7) if end at vertex 0. 8 / 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend