| | | | | |

Lazy Removal 1

  • 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_))       // t < n->value_ : go left
          n = n->lchild_;
        else if (pred_(n->value_,t))  // t > n->value_ : go right
          n = n->rchild_;
        else                          // t == n->value_ : found
        {
          n->SetDead();
          return;
        }
      }
    }

Many BST algorithms need to be modified to test nodes for dead/alive status


| | Top of Page | 12. Binary Search Trees - 26 of 41