Technical Interview

Tips, questions, answers and puzzles at
www.technical-interview.com

Thursday, April 22, 2010

What are the advantages and disadvantages of linked list structure vs. arrays?

Q:

What are the advantages and disadvantages of linked list structure vs. arrays?

A:

Linked lists allow only sequential access to elements O(n) while arrays allow random access O(1). Linked lists requires an extra storage for references, which often makes them impractical for lists of small data items such as characters or Boolean values. From the over side, size of array is restricted to declaration. Insertion/Deletion of values in arrays are very expensive comparing to linked list and requires memory reallocation. Elements can be inserted into linked lists indefinitely, while an array will eventually.

No comments:

Post a Comment