Array Vs Linked List
- Array and linked list are having 4 main difference....
- Element Access
- Memory Structure
- Insertion / Deletion
- 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.
- 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 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
thnx sir.......
ReplyDeleteSir,what is static load and dynamic load ?It was asked in an interview somewhere.
ReplyDeleteAt compile time memory is loaded it is called " Static Load" and Run time memory is loaded is called "Dynamic Load".
Deletethanku sir..
Delete