Data Structures Union Find Algorithm Theory WS 2012/13 Fabian Kuhn - - PowerPoint PPT Presentation

data structures
SMART_READER_LITE
LIVE PREVIEW

Data Structures Union Find Algorithm Theory WS 2012/13 Fabian Kuhn - - PowerPoint PPT Presentation

Chapter 4 Data Structures Union Find Algorithm Theory WS 2012/13 Fabian Kuhn Union Find Data Structure Also known as Disjoint Set Data Structure Manages partition of a set of elements set of disjoint sets Operations:


slide-1
SLIDE 1

Chapter 4

Data Structures

Union Find

Algorithm Theory WS 2012/13 Fabian Kuhn

slide-2
SLIDE 2

Algorithm Theory, WS 2012/13 Fabian Kuhn 2

Union‐Find Data Structure

Also known as Disjoint‐Set Data Structure… Manages partition of a set of elements

  • set of disjoint sets

Operations:

  • _: create a new set that only contains element
  • : return the set containing
  • , : merge the two sets containing and
slide-3
SLIDE 3

Algorithm Theory, WS 2012/13 Fabian Kuhn 3

  • Represent each set by a tree
  • Representative of a set is the root of the tree
  • Disjoint‐Set Forests
slide-4
SLIDE 4

Algorithm Theory, WS 2012/13 Fabian Kuhn 4

Disjoint‐Set Forests

_: create new one‐node tree : follow parent point to root (parent pointer to itself) , : attach tree of to tree of

slide-5
SLIDE 5

Algorithm Theory, WS 2012/13 Fabian Kuhn 5

Union‐By‐Size Heuristic

Union of sets and :

  • Root of trees representing and :

and

  • W.l.o.g., assume that ||
  • Root of ∪ :

( is attached to as a new child)

Theorem: If the union‐by‐rank heuristic is used, the worst‐case cost of a ‐operation is Proof:

slide-6
SLIDE 6

Algorithm Theory, WS 2012/13 Fabian Kuhn 6

Union‐Find Algorithms

Recall: operations, of the operations are make_set‐operations Linked List with Weighted Union Heuristic:

  • make_set: worst‐case cost 1
  • find

: worst‐case cost 1

  • union

: amortized worst‐case cost log Disjoint‐Set Forest with Union‐By‐Size Heuristic:

  • make_set: worst‐case cost 1
  • find

: worst‐case cost log

  • union

: worst‐case cost log Can we make this faster?

slide-7
SLIDE 7

Algorithm Theory, WS 2012/13 Fabian Kuhn 7

Path Compression During Find Operation

: 1. if . then 2. . ≔ find . 3. return .

slide-8
SLIDE 8

Algorithm Theory, WS 2012/13 Fabian Kuhn 8

Complexity With Path Compression

When using only path compression (without union‐by‐rank): : total number of operations

  • of which are find‐operations
  • of which are make_set‐operations

 at most 1 are union‐operations Total cost: ⋅ ⋅

slide-9
SLIDE 9

Algorithm Theory, WS 2012/13 Fabian Kuhn 9

Union‐By‐Size and Path Compression

Theorem: Using the combined union‐by‐size and path compression heuristic, the running time of disjoint‐set (union‐find)

  • perations on elements (at most make_set‐operations) is

⋅ , , Where , is the inverse of the Ackermann function.

slide-10
SLIDE 10

Algorithm Theory, WS 2012/13 Fabian Kuhn 10

Ackermann Function and its Inverse

Ackermann Function: For , ℓ 1, , ℓ ≔ ℓ, , ℓ , , , ℓ , , ℓ , , ℓ Inverse of Ackermann Function: , ≔ | , ⁄

slide-11
SLIDE 11

Algorithm Theory, WS 2012/13 Fabian Kuhn 11

Inverse of Ackermann Function

  • , ≔ min 1 | ,

⁄ log

⟹ , ⁄ , 1 ⟹ , min 1| , 1 log

  • 1, ℓ 2ℓ, , 1 1,2,

, ℓ 1, , ℓ 1