Under what circumstances are Linked Lists useful?

Technology CommunityCategory: Data StructuresUnder what circumstances are Linked Lists useful?
VietMX Staff asked 3 years ago

Linked lists are very useful when you need :

  • to do a lot of insertions and removals, but not too much searching, on a list of arbitrary (unknown at compile-time) length.
  • splitting and joining (bidirectionally-linked) lists is very efficient.
  • You can also combine linked lists – e.g. tree structures can be implemented as “vertical” linked lists (parent/child relationships) connecting together horizontal linked lists (siblings).

Using an array based list for these purposes has severe limitations:

  • Adding a new item means the array must be reallocated (or you must allocate more space than you need to allow for future growth and reduce the number of reallocations)
  • Removing items leaves wasted space or requires a reallocation
  • inserting items anywhere except the end involves (possibly reallocating and) copying lots of the data up one position