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:
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".
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With