Data Structures19 sections · 729 units
Open in Course

The Access Operation

Core of Link-Cut trees

Access(v) makes the path from v to the root a single preferred path, with v at the bottom.

function access(v)
    splay(v)
    // Detach right subtree (deeper nodes)
    if v.right then
        v.right.pathParent := v
        v.right.parent := null
    v.right := null

    last := null
    // Walk up, switching preferred paths
    while v.pathParent is not null
        w := v.pathParent
        splay(w)
        // Detach w's current preferred child
        if w.right then
            w.right.pathParent := w
            w.right.parent := null
        // Make v the preferred child
        w.right := v
        v.parent := w
        v.pathParent := null
        splay(v)
        last := w

    return last // last path-parent; used for LCA

After access(v), v is root of its auxiliary tree and connected by preferred edges to the tree root.