-3

In an interview I was asked when is an array preferred over a linked list? The interviewer wasn't satisfied with the differences that I gave,he was actually asking for some examples.

bsn
  • 1
  • 1
  • 1
    Here the answer that you are looking for: http://stackoverflow.com/questions/393556/when-to-use-a-linked-list-over-an-array-array-list – juanmajmjr Jul 13 '15 at 21:48
  • I would like to know the scenarios rather than the differences mentioned in the link. – bsn Jul 13 '15 at 21:55

1 Answers1

0

Some examples or usage of array and linked list are.

Arrays.

Arrays are used when the number of items to be stored are known beforehand.

Arrays are used when we want to access the elements through their index (binary search).

Arrays use less memory as compared to linked list.

Sorting in an array is easier.

Linked list.

Linked list is used when amount of data is not known beforehand.

Linked list takes more memory, as it uses pointer field.

Linked list is comparatively hard to implement.

Sorting a linked list is quite difficult.
Anuj Garg
  • 584
  • 7
  • 22