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.

11.21 Bounded Node Priority Queues ( b node pq )<br />

1. Definition<br />

An instance of the data type b node pq is a priority queue of nodes with integer<br />

priorities with the restriction that the size of the minimal interval containing all priorities<br />

in the queue is bounded by N, the minimum priority is never decreasing, and every node is<br />

contained in at most one queue. When applied to the empty queue the del min - operation<br />

returns a special default minimum node defined in the constructor of the queue.<br />

#include < <strong>LEDA</strong>/graph/b node pq.h ><br />

2. Creation<br />

b node pq PQ;<br />

introduces a variable PQ of type b node pq and initializes it<br />

with the empty queue with default minimum node nil.<br />

b node pq PQ(node v);<br />

3. Operations<br />

introduces a variable PQ of type b node pq and initializes it<br />

with the empty queue with default minimum node v.<br />

node PQ.del min( ) removes the node with minimal priority from PQ and<br />

returns it (the default minimum node if PQ is empty).<br />

void PQ.insert(node w, int p) adds node w with priority p to PQ.<br />

void PQ.del(node w, int = 0) deletes node w from PQ.<br />

4. Implementation<br />

Bounded node priority queues are implemented by cyclic arrays of doubly linked node<br />

lists.<br />

5. Example<br />

Using a b node pq in Dijktra’s shortest paths algorithm.<br />

int dijkstra(const GRAPH& g, node s, node t)<br />

{ node_array dist(g,MAXINT);<br />

b_node_pq PQ(t); // on empty queue del_min returns t<br />

dist[s] = 0;<br />

for (node v = s; v != t; v = PQ.del_min() )

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

Saved successfully!

Ooh no, something went wrong!