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.

Iteration<br />

forall items(it, S) { “the items of S are successively assigned to it” }<br />

forall rev items(it, S) { “the items of S are successively assigned to it in reverse order”<br />

}<br />

forall(i, S) { “the informations of all items of S are successively assigned to i” }<br />

forall defined(k, S) { “the keys of all items of S are successively assigned to k” }<br />

5. Implementation<br />

Sorted sequences are implemented by skiplists [77]. Let n denote the current size of<br />

the sequence. Operations insert, locate, lookup and del take time O(log n), operations<br />

succ, pred, max, min item, key, inf , insert at and del item take time O(1). clear takes<br />

time O(n) and reverse items O(l), where l is the length of the reversed subsequence.<br />

Finger lookup(x) and finger locate(x) take time O(log min(d, n − d)) if x is the d-th item<br />

in S. Finger lookup from front(x) and finger locate from front(x) take time O(log d) if x<br />

is the d-th item in S. Finger lookup from rear(x) and finger locate from rear(x) take time<br />

O(log d) if x is the n−d-th item in S. Finger lookup(it, x) and finger locate(it, x) take time<br />

O(log min(d, n−d)) where d is the number of items between it and the item containing x.<br />

Note that min(d, n−d) is the smaller of the distances from it to x if sequences are viewed<br />

as circularly closed. Split, delete subsequence and conc take time O(log min(n 1 , n 2 )) where<br />

n 1 and n 2 are the sizes of the results of split and delete subsequence and the arguments of<br />

conc respectively. Merge takes time O(log((n 1 + n 2 )/n 1 )) where n 1 and n 2 are the sizes<br />

of the two arguments. <strong>The</strong> space requirement of sorted sequences is linear in the length<br />

of the sequence (about 25.5n Bytes for a sequence of size n plus the space for the keys<br />

and the informations.).<br />

6. Example<br />

We use a sorted sequence to list all elements in a sequence of strings lying lexicographically<br />

between two given search strings.<br />

#include <br />

#include <br />

using leda::sortseq;<br />

using leda::string;<br />

using leda::seq_item;<br />

using std::cin;<br />

using std::cout;

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

Saved successfully!

Ooh no, something went wrong!