S 3 identified by a rep. identified by a rep. n n = # of = # - - PDF document

s 3 identified by a rep identified by a rep n n of of
SMART_READER_LITE
LIVE PREVIEW

S 3 identified by a rep. identified by a rep. n n = # of = # - - PDF document

Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets { } = Collection of disjoint sets Collection of disjoint sets S S S , , S , , S 1 2 3 n


slide-1
SLIDE 1

1

Data Structures for Disjoint Sets Data Structures for Disjoint Sets

1

S

2

S

3

S

n

S

  • {

}

1 2 3

, , , ,

n

S S S S S = …

Collection of disjoint sets Collection of disjoint sets Each set is an Each set is an “ “equiv. Class

  • equiv. Class”

” identified by a rep. identified by a rep. Make_Set(x Make_Set(x) ) … … Create the Create the singleton set with singleton set with x x as rep. as rep.

{ }

x

S x =

Find_Set(x Find_Set(x) ) Return pointer to Return pointer to set rep of set rep of Union(x,y Union(x,y) ) … … Create with set rep and Create with set rep and destroy & destroy &

x y

S S ∪

x

S

y

S Data Structures for Disjoint Sets Data Structures for Disjoint Sets

Parameters Parameters

  • n

n = # of = # of Make Make-

  • Set

Set ops

  • ps
  • m

m = # of all ops = # of all ops { {Make_Set Make_Set, Union, , Union, Find_Set Find_Set} }

  • #

# Unions Unions

  • m

n ≥ 1 n ≤ − ≤ − Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets

slide-2
SLIDE 2

2

Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets Data Structures for Disjoint Sets

1 2 1

( 1) 1 2 3 ( 1) ( ) 2

n j

n n n j O n

− =

− + + + + + + + − = = =

Weighted Weighted-

  • Union Heuristic

Union Heuristic

  • Each rep has a

Each rep has a Length Length-

  • of
  • f-
  • List

List field field

  • Use this to append smaller sets to larger

Use this to append smaller sets to larger

  • nes
  • nes

Theorem

  • Theorem. If the

. If the Linked Linked-

  • List representation

List representation

  • f sets and if the
  • f sets and if the weighted

weighted-

  • union heuristic

union heuristic are used, and if a sequence of are used, and if a sequence of m m { {Make_Set Make_Set, Union, , Union, Find_Set Find_Set} ops are used } ops are used (with (with n n Make Make-

  • Set ops

Set ops), then the ), then the computational time taken is computational time taken is

( ) ( )

lg O m n n + Disjoint Disjoint-

  • Set Forest Representation

Set Forest Representation

Union Union

A Problem A Problem Data Structures for Disjoint Sets Data Structures for Disjoint Sets

slide-3
SLIDE 3

3

Data Structures for Disjoint Sets Data Structures for Disjoint Sets Heuristics to Improve Running Time Heuristics to Improve Running Time

  • Union by Rank

Union by Rank

  • Path Compression

Path Compression

Each node has a field containing Each node has a field containing Rank Rank, which , which is an upper bound on the height of the node is an upper bound on the height of the node