Monday, June 2, 2008

What are the advantages of linked lists?

The main advantage of linked lists is that they can be expanded in constant time without memory overhead.

While creating array you must allocate memory for a certain number of elements. If you want to add more elements to the array than you allocated for you must create a new array and copy the old array into the new array. This can take lots of time. You can prevent this by allocating lots of space initially but then you might allocate more than you need wasting memory.

If you want to make insertions in between the array you need to move elements, which another overhead.

With a linked list you can start with space for just one element allocated. And add on new elements easily without the need to do any copying and reallocating.

You can make frequent insertions and deletions into linked list.

No comments: