| | | | | |

Lazy Removal

  • Removal of nodes in BST possible (see text)
  • Removal in height-balanced BSTs is complicated further by property maintenance
  • Lazy removal: make no change in tree structure, just mark node as "dead"
  • Dead nodes (aka "tombstones") remain in structure and aid in tree navigation
  • Dead nodes are restored to active duty when their value is called again
  • When too many dead nodes exist, call Rehash() to eliminate all tombstones
  • We will use the name Erase(t) for lazy removal of t from the structure
    void Erase(const T& t)
    {
      Node * n = root_;
      while(n)
      {
        if (pred_(t,n->value_))       // k < n->key_ : go left
          n = n->lchild_;
        else if (pred_(n->value_,t))  // k > n->key_ : go right
          n = n->rchild_;
        else                          // k == n->key_ : found
        {
          n->SetDead();
          return;
        }
      }
    }

Other search and insert algorithms need to be modified to test nodes for dead/alive status


| | Top of Page | 13. Balanced BSTs - 21 of 35