Difference Between Array and Linked List

Array Vs Linked List

  • Array and linked list are having 4 main difference....
        1. Element Access
        2. Memory Structure
        3. Insertion / Deletion
        4. Memory Allocation

Element Access

  • Stack elements can be randomly Accessed using Subscript e.g array[0],array[1] can be randomly accessed.
  • While In Linked List We have to Traverse Through the Linked List for Accessing Element. So O(n) Time required for Accessing Element.
  • Generally In linked List Elements are accessed Sequentially.
Memory Structure
  • Stack is stored in contiguous Memory Locations.
  • Element is stored at any available Location , but the Pointer to that memory location is stored in Previous Node. 
Insertion / Deletion
  • As the Array elements are stored in Consecutive memory Locations so insertion and deletion is allowed.
  • In Linked List we have to Just Change the Pointer address field ,So Insertion and Deletion Operations are quite easy to implement.
Memory Allocation
  • Memory Should be allocated at Compile-Time in Stack.
  • In Linked list memory can be allocated at Run-Time.
  • Stack uses Static Memory Allocation.
  • Linked List Uses Dynamic Memory Allocation

4 comments:

  1. Sir,what is static load and dynamic load ?It was asked in an interview somewhere.

    ReplyDelete
    Replies
    1. At compile time memory is loaded it is called " Static Load" and Run time memory is loaded is called "Dynamic Load".

      Delete