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.14 Dynamic Trees ( dynamic trees )<br />

1. Definition<br />

An instance D of the data type dynamic trees is a set of dynamically changing rooted<br />

trees. Each edge is directed towards the root and has a weight. Optionally, user defined<br />

information can be stored at the vertices and at the edges.<br />

Remark Dynamic trees are very similar to the data type tree collection. <strong>The</strong> main difference<br />

is that the former use edge weights instead of the node weights used by the latter.<br />

#include < <strong>LEDA</strong>/core/dynamic trees.h ><br />

2. Creation<br />

dynamic trees D;<br />

creates an empty instance D of type dynamic trees.<br />

3. Operations<br />

vertex D.make(void ∗ x = nil)<br />

creates a tree containing a single node v which is returned.<br />

<strong>The</strong> additional user defined information x is<br />

stored at v.<br />

void∗ D.vertex inf(vertex v) returns the additional user defined information at v.<br />

void∗ D.edge inf(vertex v)<br />

vertex D.parent(vertex v)<br />

returns the additional user defined information at<br />

(v,parent(v)) or nil, if v has no parent.<br />

returns the parent of v in the tree or nil.<br />

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

double D.cost(vertex v)<br />

vertex D.mincost(vertex v)<br />

returns the cost of (v,parent(v)).<br />

Precondition: v is not a tree root.<br />

returns vertex w closest to root(v) s.t. (w,parent(w))<br />

has minimal cost on the path v → root(v).<br />

Precondition: v is not a tree root.<br />

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

adds x to each edge on the path v → root(v).<br />

void<br />

D.link(vertex v, vertex w, double x, void ∗ e inf = nil)<br />

links the tree root v (prec.) to the vertex w in a different<br />

tree (prec.). <strong>The</strong> edge e = (v, w) gets weight<br />

x, and the additional user defined information e i nf is<br />

stored at e.<br />

double D.cut(vertex v)<br />

deletes the edge (v,parent(v)) and returns its weight.<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!