Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are real world examples of when Linked Lists should be used?

Another programmer was mentioning that they haven't found a use case for using a linked list data structure in any professional software in his career. I couldn't think of any good examples off the top of my head. He is mostly a C# and Java developer

Can anyone give some examples where this was the correct data structure to solve a particular real world problem?

Related: What is a practical, real world example of the Linked List?

like image 241
leora Avatar asked Mar 21 '09 22:03

leora


People also ask

What is the real life example of linked list?

Image viewer – Previous and next images are linked and can be accessed by the next and previous buttons. Previous and next page in a web browser – We can access the previous and next URL searched in a web browser by pressing the back and next buttons since they are linked as a linked list.

When would a linked list be useful?

Linked lists are often used because of their efficient insertion and deletion. They can be used to implement stacks, queues, and other abstract data types.


2 Answers

Linked Lists offer several advantages over comparable data structures such as static or dynamically expanding arrays.

  1. LinkedLists does not require contiguous blocks of memory and therefore can help reduce memory fragmentation
  2. LinkedLists support efficient removal of elements (dynamic arrays usually force a shift in all of the elements).
  3. LinkedLists support efficient addition of elements (dynamic arrays can cause a re-allocation + copy, if a particular add exceeds the current capacity)

Any place where these advantages would be significantly valuable to a program (and the disadvantages of a LinkedList were negligible) would be a place to use a LinkedList.

like image 109
JaredPar Avatar answered Sep 21 '22 21:09

JaredPar


A real-world example would be a FIFO queue. An simple array-based list is pretty bad for that because you need to add at one end and remove at the other end, and one of those operations will be O(n) with an array-based list (unless you add extra logic to work with a start AND end index), while both are O(1) with a linked list without extra effort.

like image 24
Michael Borgwardt Avatar answered Sep 18 '22 21:09

Michael Borgwardt