Array & Linked List Difference between in DS

  

Slno. Array Linked List
01. They are static, i.e. size of an array is fixed. They are dynamic, i.e. size of a list is not fixed.
02. Memory is allocated/formed in the form of a stack. Memory is allocated/formed in the form of a heap.
03. Random access is efficient. Random access is inefficient.
04. Elements rearranging is difficult/inefficient. Elements rearranging is easy/efficient.
05. It is necessary to specify the number of elements for an array during declaration/ compile time. It is not necessary to specify the number of elements for a list during declaration/ memory is allocated during run time.
06. It occupies less memory than a linked list for the same number of elements. It occupies more memory.
07. Inserting new elements at the front is potentially expensive because existing elements need to be shifted over to make room. Inserting a new element at any position can be carried out easily.
08. Deleting an element from an array is not possible. Deleting an element from a list is possible. 
09. Overhead per element is none. Overhead per element is for 1 or 2 links.

            

Difference between Malloc() & Calloc()

Slno. calloc() malloc()
01. The calloc() function allocates multiple blocks of requested memory. The malloc() function allocates a single block of requested memory.
02. It initializes the created memory with zero hence no garbage values are present in the memory. It does not initialize the memory during allocation hence garbage values are present in the memory.
03. It takes two arguments. It takes only one argument.
04. calloc() is better than malloc() due to no garbage values in allocated memory. malloc() is less better than calloc() due to garbage values being present in allocated memory.
05. calloc() is more secure and provides more space during allocation than malloc().  malloc() is less secure and provides less space during allocation than calloc(). 
06. calloc function is normally used for allocating memory to derived data types such as arrays and structures. If it fails to allocate enough space as specified, it returns a NULL pointer. We use malloc() when we need to allocate objects that must exist beyond the lifetime of execution of the current block, or if we need to allocate memory greater than the size of that stack. 
07.  calloc() is comparatively slower. malloc() is comparatively faster.
08. The calloc() is used to allocate multiple blocks of memory space having the same block size. malloc() is used to allocate a large single block of memory space.

                      

Difference between Static Memory Allocation & Dynamic Memory Allocation

Slno. Static Memory Allocation Dynamic Memory Allocation
01. Memory is allocated before the execution of the program begins/starts i.e. during compilation time. Memory is allocated during the execution of the program i.e. at run time.
02. Implemented using the stacks data structure. Implemented using the heap data structure.
03. Less efficient method and less used. More efficient method and is mostly used.
04. There is no memory reusability. There is memory reusability and memory can be freed when not required.
05. Variables remain permanently allocated. Memory is allocated only when the program unit is active.
06. In this type of allocation, memory cannot be resized again after the initial allocation. In this type of allocation, memory can be dynamically expanded and shrunk as needed in the program.
07. Faster execution than Dynamic. Slower execution than Static.
08. Implementation of this type of memory allocation is comparatively simple. Implementation of this type of memory allocation is comparatively complicated.
09. In static memory allocation, we cannot reuse the unused memory i.e. memory wasting occurs. Memory can be freed when it is no longer needed & reused or reallocated during execution. Hence no memory wasting occurs.

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.