Data Structures19 sections · 729 units
Open in Course

Splay with Push Down

Handling lazy flags

Before splaying, push down lazy flags along the path:

function splay(x)
    // Push down from root to x
    pushDownPath(x)

    while not x.isRoot()
        p := x.parent
        if not p.isRoot()
            g := p.parent
        pushDown(g)
        pushDown(p)
        pushDown(x)

        if not p.isRoot()
            g := p.parent
            if (x = p.left) = (p = g.left) then
                rotate(p)
            else
                rotate(x)
        rotate(x)
    pushUp(x)

function pushDownPath(x)
    if not x.isRoot() then
        pushDownPath(x.parent)
    pushDown(x)

Push down ensures lazy values are applied before we rotate.