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

disjoint sets part 2
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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}}: 1 2 3 4 5 6 7 2 3 3 3 2

1 / 8

slide-2
SLIDE 2

Disjoint Sets using UpTrees

S = {{0, 1, 4}, {2, 7}, {3, 5, 6}, {8}}

4 1 2 7 3 5 6 8

int DS::Find( int k ) { if( parent[k] == k ) return k; else return Find( parent[k] ); } Find runtime depends on? void Link(int root1, int root2) { parent[root__] = root__; } void DS::Union(int k1, int k2) { Link(Find(k1),Find(k2)); }

2 / 8

slide-3
SLIDE 3

Smart Union

4 1 3 5 8 6

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

slide-4
SLIDE 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]; } }

4 1 3 5 8 6

4 / 8

slide-5
SLIDE 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]; } }

4 1 3 5 8 6 2 7 Find(2) 3 7 1 4 2 5 6 8

5 / 8

slide-6
SLIDE 6

Running time with smart union and path compression

Iterated logarithm lg∗ n

lg∗ n =

  • if n ≤ 1

1 + lg∗(lg n)

  • therwise

In other words, lg∗ n is the number of times we can take lg iteratively until the result is at most 1. Example: lg∗(265536) =

The number of atoms in the universe is estimated to be at most 2273.

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

slide-7
SLIDE 7

planar relative neighbor- hood Gabriel Urquhart strongly regular@ 2-strongly regular@ k-outer- planar polyhedral maximal planar homoth. triangle contact bar visibility strict B1-VPG contact

  • dd-hole

free@ triangle- free@ C4-C5-K4- diamond- free@ domination perfect@ E-free@ unit… partial 3-tree@ Laman bipartite@ C4- triangle- free Halin series- parallel chordal@ C4-C6- C8-K1,4-

  • dd cycle-

free

  • uter-

planar Apollonian network 2-tree 2-sub- division@ cactus SC 2-tree bipartite ∩ claw-free median@ 2term … hamilt. ▽ probe interval unicyclic 2-outer- planar tree tolerance ∩ tree partial grid ▼ probe interval ∩ tree caterpillar K2-free binary tree lin. convex tr.grid graph 2-con nected ◀ triang. grid graph solid … locally connected ▼ Hn,q-grid gid grid graph solid … deg≤3 ▼ partial grid cubic@ planar deg≤4 bipartite ▼ bipartite ▶ planar deg≤3 4-regu- lar@ 2-con nected ▼

Planar Graphs

by Tamara Mchedlidze

☜ graph class ☜ class of bounded degree graphs ☜ class of grid-like structured graphs ☜ class of trees

A B B A class A includes class B

label abbreviation class A@

class A ∩ planar graphs class A…

class A + name of the unique ancestor class A▼

class A ∩ unique ancestor class A◀

class A ∩ left ancestor class A ▶

class A ∩ right ancestor

Graphs

7 / 8

slide-8
SLIDE 8

Graphs

1 2 3 4 5 6 1 2 3 4 5

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