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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.15 Dynamic Collections of Trees ( tree collection )<br />

1. Definition<br />

An instance D of the parameterized data type tree collection is a collection of vertex<br />

disjoint rooted trees, each of whose vertices has a double-valued cost and contains an<br />

information of type I, called the information type of D.<br />

#include < <strong>LEDA</strong>/core/tree collection.h ><br />

2. Creation<br />

tree collection D;<br />

creates an instance D of type tree collection, initialized with the<br />

empty collection.<br />

3. Operations<br />

d vertex D.maketree(I x) adds a new tree to D containing a single vertex v<br />

with cost zero and information x, and returns v.<br />

const I& D.inf(d vertex v) returns the information of vertex v.<br />

d vertex D.findroot(d vertex v) returns the root of the tree containing v.<br />

d vertex D.findcost(d vertex v, double& x)<br />

sets x to the minimum cost of a vertex on the tree<br />

path from v to findroot(v) and returns the last<br />

vertex (closest to the root) on this path of cost x.<br />

d vertex D.parent(d vertex v) returns the parent vertex of v.<br />

void D.addcost(d vertex v, double x)<br />

void D.link(d vertex v, d vertex x)<br />

adds double number x to the cost of every vertex<br />

on the tree path from v to findroot(v).<br />

combines the trees containing vertices v and w by<br />

adding the edge (v, w). (We regard tree edges as<br />

directed from child to parent.)<br />

Precondition: v and w are in different trees and v<br />

is a root.<br />

void D.cut(d vertex v) divides the tree containing vertex v into two trees<br />

by deleting the edge out of v.<br />

Precondition: v is not a tree root.

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

Saved successfully!

Ooh no, something went wrong!