Every other link-cut operation starts with access 57:49, 1:12:57.
What it must accomplish
- Make the root-to-
vpath preferred inv's represented tree58:14,59:34. - That forces preferred-child changes: some formerly preferred edges stop being preferred and the paths must be re-split and re-merged
58:40,58:59. - After the access,
vhas no preferred child (by the definition), so its old preferred child must be cut off1:00:05. - Goal state:
vis the root of the root aux tree of the tree of aux trees1:00:45,1:01:03,1:01:40.
Step 1 — splay v and detach its descendants
- Splay
vinside its own aux tree sovbecomes that tree's root1:02:18. - Keyed by depth ⇒ the right subtree holds
v's descendants on the path, which are no longer preferred. Detach it as its own aux tree1:03:08,1:03:29.
r = v.right
r.path_parent = v # the old preferred edge becomes a path-parent pointer
r.parent = none
v.right = none
Step 2 — walk up, splicing aux trees together (loop)
vnow has a path-parent pointer to somewin another aux tree;wneed not be that tree's root1:04:53.- Who is
w? the represented-tree parent of the minimum-keyed (shallowest) element ofv's aux tree, i.e. the parent of the top ofv's path1:05:17. - Splay
wto the root of its aux tree, then swapw's old preferred descendants forv's path:
splay(w)
w.right.path_parent = w # w's OLD preferred child becomes a path parent
w.right.parent = none
w.right = v # v's path becomes w's new preferred descendant
v.parent = w
v.path_parent = w.path_parent # v/w path-parent bookkeeping
w.path_parent = none
splay(v) # bring v back up
1:05:43, 1:06:18, 1:06:32, 1:07:01, 1:07:29, 1:08:03
- Repeat in a while loop until
vsits in the root aux tree, then splay once more1:08:29. - Nelson's own warning after nearly dropping it: "you need to make sure you maintain the path parents"
1:09:20,1:09:37.
Why the splice is legal
- Everything spliced under
won the right is at greater depth thanw, since it all hangs offwin the represented tree — so BST order by depth is preserved1:10:41,1:11:15. - In effect: splice two paths together and cut off whatever hung below
wbefore, becausew's preferred child just changed1:10:11,1:10:41. - Net effect of each splice step: a parent pointer becomes a path-parent pointer and vice versa
1:07:01.