Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is lazy deletion advantageous/disadvantageous to a binary tree or linked list?

Recently, for a data structures class, I was asked the question of how a lazy deletion (that is, a deletion that first marks the items needed to be deleted, and then at some time later deletes all the marked items) would be advantageous/disadvantageous to an array, linked list, or binary tree. Here is what I have come up with:

  • This would help arrays because you would save the time that is taken to shift the array every time an index is deleted although in algorithms that need to traverse the array, there could be inefficiencies.
  • This would not help linked lists because you need to traverse O(n) to mark an item to be deleted anyways.
  • I'm not entirely sure about binary trees, but if it were a linked list implementation of one I would imagine it is like the linked list?
like image 262
Matt Avatar asked Oct 11 '11 21:10

Matt


People also ask

What are the advantages and disadvantages of lazy deletion?

Advantages: It takes less time to mark a node as deleted than to change pointers. Disadvantages: Once a node has been "lazily deleted" it still needs to be traversed in a search for another node. Also, you then use up a lump amount of time to delete all the "lazily deleted elements".

What is lazy deletion binary tree?

A lazy-deletion binary search tree is a binary search tree where erased objects are simply tagged as erased while the nodes themselves remain in the tree. Occasionally, a member function may be called to clean up (delete) all erased nodes at once.

What are the disadvantages of linked list?

Disadvantages of Linked Lists:Use of pointers is more in linked lists hence, complex and requires more memory. Searching an element is costly and requires O(n) time complexity. Traversing is more time consuming and reverse traversing is not possible in singly linked lists.

What is a lazy deletion strategy?

In computer science, lazy deletion refers to a method of deleting elements from a hash table that uses open addressing. In this method, deletions are done by marking an element as deleted, rather than erasing it entirely. Deleted locations are treated as empty when inserting and as occupied during a search.


1 Answers

I think it all depends on the circumstances and the requirements. In a general sense using this method where they are marked and then deleted later they all have a lot of similar pros and cons.

Similar pros: -When marked for deletion there is no shifting of the data structures, which makes deletion much faster. -You can insert on top of a deleted item, which means no shifting for inserts either, plus insertion can be done faster since it can write over the first delete instead of looking for the end of a list

Similar cons: -Waste of space for deleted item, since they are just sitting there -Have to transverse twice to delete an item, once to mark it and once again to delete it -Many marked items for deletion will pollute the data structure making searches take longer since deleted items have to be searched over.

like image 55
Michael Wildermuth Avatar answered Oct 14 '22 05:10

Michael Wildermuth