Implementation of the delete algorithm