Sunday, 17 September 2017

At what points Linear arrays and Linked Lists are given preferences with respect to each others? 

Use Linked Lists are given preferable over Linear Arrays when we have below mentioned scenario:
  • When we need a constant-time insertions or deletions from the linked list.
  • When we don't know in advance that, how many items will be in the list?
  • When we don't need any types of random access to any elements of the linked list.
  • When we want to insert elements in the middle of the linked list.

Use Linear Arrays are given preferable over Linked Lists when we have below mentioned scenario:
  • When we need random access to our data elements.
  • When the total number of elements inserted are known in advance, so that memory should be allocated in advance.
  • Array take less memory then Linked list. A completely filled linear array take less memory then linked lists.
  • When we need to access the data at any position at O(1).


Thanks
Mukesh Rajput

No comments:

Post a Comment

Thanks
Mukesh Rajput