Arrays vs Linked List

I think everyone knows the use cases of Arrays and Linked List but revising things wont hurt :)

Array:

  • One memory block 
  • 0-based indexing
  • Easier to use and access
  • Constant access time
  • Fixed size
  • Delete and Insert in front or middle is expensive

Linked List:

  • Elements are not stored in contiguous memory locations
  • Extra memory needed to save pointer for next element
  • Searching any element is expensive.
  • Insert and Delete is very cheap. Constant time.
  • No memory limitation as long as system has enough memory.
  • Easier to store different data size.
There are some good comparison listed on Wiki. Also you will get the tradeoff between above two data structures.

Comments

Popular posts from this blog

Scala Learning: Finding Square Root

Deleting a hidden user in MAC

Problem Solving: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node