Basic Principles
Preferred-path decomposition:
Preferred child of node v means: * none if last access in V ‘s subtree=V * W if w is the last access in V’ s subtree.
Preferred path decomposes nodes in represented tree. Trees are separated.
Auxiliary trees:
Used in Tango Trees.
Represent each preferred path by splay trees / Tango trees / RB Trees. To key the nodes by depth. As seen by the video, the depth of the nodes are sorted. Nodes indexed in a balanced tree by depth.
Route of each aux. tree called a path parent (similar to Tree chain partition) as defined as top[]
.
Following one ‘s parent=find the predecessor in aux. tree. The actual parent of a subtree / aux. tree is the leftest node in the aux. tree, where the path parent’ s pointer should be indexed in the aux. tree ‘s root.
Take all the aux. trees with their path parents, we have a tree of aux. trees.
access () operation:
The most crucial operation in LCTs. Functions: * Make your life easy. * make Root-> V path preferred. * make V the root of its aux. tree (which is equivalent to: V is the root of tree of aux. trees, this is easier if using Splay trees).
- splay (V) within V’ s aux. tree. lchildren of V has smaller depths and vice versa. V now does not have preferred child, so we need to disconnect its preferred edge.
- Remove V ‘s preferred child in aux. tree:
- v. right. pathparent=v
- v. right. parent=null
- v. right=null
- Loop until v. pathparent=null
- w=v. pathparent
- splay (w) in aux. tree
- unlink w. right keeping w. right. pathparent
- w. right=v
- splay (v) for convenience in aux. tree / actually a rotate (v)
Query operations
findroot (v)
Find the root of the tree containing v.
- access (v)
- find leftest child of v and make it=r
- splay (r) / access (r) for log (n) amortized complexity
pathaggregate (v)
Find the sum of all weights on v’ s path to root
- access (v)
- return v. ltree. aggregation
access () makes our life easier.
Modify operations
cut (v)
Cut v from its parent / lives in another separate tree
- access (v)
- v. left. parent=null
- v. left=null
link (v, w)
Link v (the root of its tree) to w ‘s tree under w.
- access (v)
- access (w)
- v. left=w (it is guranteed that v. left=null)
- w. parent=v
Code implementation
Too lazy to write one...... Might add a post later.