Data Structures19 sections · 729 units
Open in Course

Cut Operation

Remove an edge

Remove the edge from u to its parent:

function cut(u)
    access(u)
    // u's parent is the rightmost node in left subtree
    if u.left is not null
        u.left.parent := null
        u.left := null

After access(u), the path from u to root is in one auxiliary tree. u's left subtree contains all ancestors. By detaching it, you cut u from its parent.

Alternative (cut edge u-v):

function cut(u, v)
    makeRoot(u)
    access(v)
    // Now u is direct left child of v
    v.left.parent := null
    v.left := null

Time: O(logn)O(\log n) amortized.