|
ADS
Algorithms and Data Structures
|
the join of the treaps; A gives also priority( t ), of a node More...
#include <ADS/tree/JoinAlgorithms.h>
Public types | |
| using | Node = typename A::Node |
| the type of the nodes | |
Static public member functions | |
| static Node * | join (Node *l, Node *m, Node *r) |
| the join of the treaps \( l \) and \( r \) with \( m \) between them, in \( O( \log n ) \) expected time | |
the join of the treaps; A gives also priority( t ), of a node
| using ADS::TreapJoin< A >::Node = typename A::Node |
the type of the nodes
|
static |
the join of the treaps \( l \) and \( r \) with \( m \) between them, in \( O( \log n ) \) expected time
In pseudocode (Blelloch and Reid-Miller, beyond the book), \( p \) the priority, \( p( \textbf{nil} ) = -\infty \), the root of the result the one of highest priority among those of \( L \) and \( R \) and \( k \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{join}( L , k , R ) \cr 2 & \quad \textbf{if}\ p( L ) > p( k )\ \textbf{and}\ p( L ) \ge p( R ) \ \textbf{then} \cr 3 & \qquad ( l , k' , r ) \gets \mathrm{expose}( L );\ \textbf{return} \ \mathrm{node}( l , k' , \mathrm{join}( r , k , R ) ) \cr 4 & \quad \textbf{if}\ p( R ) > p( k )\ \textbf{then} \cr 5 & \qquad ( l , k' , r ) \gets \mathrm{expose}( R );\ \textbf{return} \ \mathrm{node}( \mathrm{join}( L , k , l ) , k' , r ) \cr 6 & \quad \textbf{return}\ \mathrm{node}( L , k , R ) \end{array}} \]