Section 5 - Lazy Deletion

4B.5.1 Lazy Deletion

An example of an additional member that can simplify algorithms is the inclusion of a boolean deleted member in a node class. This member would be set to true if the node has been remove()-d from the tree. As you have no doubt noticed, removal is one of the hardest parts of a tree ADT. If a fast removal is essential, one can use the proposed deleted member to completely resect this aspect of the problem by simply searching for the node and, if found, setting deleted = true. Clearly this will affect other algorithms like find() and insert(). However, in some cases, it actually speeds up those methods For example, if you attempt to insert() a node that is already there, but is marked deleted, all you have to do is change the deleted member back to false! This technique is called lazy deletion.

tree pic

In lazy deletion, there would have to be a garbage collection mechanism that allows the client programmers the ability to prune all the deleted nodes from the tree - to really get rid of them. This does not have to be a fast function, though, since the idea is it would only be used when the system was off-line or in a non-critical state. Here are a couple ideas:

tree pic

4B.5.2 Some Things Required of Lazy Deletion

Lazy deletion isn't all that lazy. It trades the complexity of removal with some new complexities in other methods that have to cope with the possibility that some of the nodes still hanging in the tree are "stale". Here are a few potential treacheries that must be negotiated when implementing lazy deletion:

You now have a taste for what this course is like, having immersed yourselves in a totally new data structure, the tree, from top to bottom. However, to complete the experience, you'll need to see how we apply an algorithm, called balancing, to our tree data structure to make it more efficient. This is very exciting stuff and will take us to the forefront of computer science algorithms. We'll get a glimpse of what researchers are actually doing, even today, in an attempt to make trees as fast a data structure as possible. After some great fun with this week's assignment, you will get to see what this is all about.