+ 1

Which Data Structure can be erased from beginning to its end in O(1) time??

7th Sep 2020, 12:34 PM
Rohan27
Rohan27 - avatar
2 Respostas
0
An array should be the fastest to free since it is just 1 solid block of memory. Freeing a block of memory doesn't require any operations on each byte in that block. If you had a block of 1000 bytes, freeing it doesn't involve anything like setting every byte to 0, for example. A block is usually freed with just a few integers changing value. If you don't consider an array to be a data structure, you could include array-based data structures like array-based heaps, hash tables... because completely erasing their memory would also be a matter of de-allocating the array and a few constant time operations. A linked list would be slow to free since every node could be in a separate block of memory. This means n nodes of a linked list could take O(n) time to free.
7th Sep 2020, 1:12 PM
Josh Greig
Josh Greig - avatar
0
4th Jun 2022, 2:28 PM
AKANSHA SENGAR
AKANSHA SENGAR - avatar