31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.12 Partitions ( partition )<br />

1. Definition<br />

An instance P of the data type partition consists of a finite set of items (partition item)<br />

and a partition of this set into blocks.<br />

#include < <strong>LEDA</strong>/core/partition.h ><br />

2. Creation<br />

partition P ;<br />

creates an instance P of type partition and initializes it to the empty<br />

partition.<br />

3. Operations<br />

partition item P.make block( ) returns a new partition item it and adds the block<br />

it to partition P .<br />

partition item P.find(partition item p)<br />

int P.size(partition item p)<br />

returns a canonical item of the block that contains<br />

item p, i.e., iff P.same block(p, q) then P.find(p)<br />

and P.find(q) return the same item.<br />

Precondition: p is an item in P .<br />

returns the size of the block containing p.<br />

int P.number of blocks( ) returns the number of blocks in P .<br />

bool P.same block(partition item p, partition item q)<br />

returns true if p and q belong to the same block of<br />

partition P .<br />

Precondition: p and q are items in P .<br />

void P.union blocks(partition item p, partition item q)<br />

void P.split(const list& L)<br />

4. Implementation<br />

unites the blocks of partition P containing items<br />

p and q.<br />

Precondition: p and q are items in P .<br />

turns all items in L to singleton blocks.<br />

Precondition: L is a union of blocks.<br />

Partitions are implemented by the union find algorithm with weighted union and path<br />

compression (cf. [86]). Any sequence of n make block and m ≥ n other operations (except

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!