You Don't Use Linked Lists. But They're Running Half Your Software.

You will likely never write a linked list in a production JavaScript project. Your language built-in arrays handle dynamic sizing faster. Interviewers teach you to build them on whiteboards, but this creates a wrong mental model.

You should not learn linked lists to implement them. You learn them to understand the tools you use every day.

They are everywhere: • Browser back and forward buttons. • Text editor undo history. • LRU caches in web servers and databases. • Redis list commands. • The Linux kernel process scheduler.

They are not relics. They are infrastructure.

The real reason linked lists struggle is cache locality. Your CPU does not read RAM one byte at a time. It pulls in a 64-byte chunk called a cache line.

Arrays are fast because they sit together in memory. The CPU reads the first element and gets the next 15 for free.

Linked lists destroy this. Each node sits in a different memory spot. Following a pointer forces the CPU to jump to a new address. This triggers a new RAM fetch. This costs hundreds of CPU cycles.

On modern hardware, array traversal can be 10 to 100 times faster than linked list traversal. Big-O notation ignores this constant cost.

So when do you use them?

Use a singly linked list for stacks or simple task queues where you only add or remove from one end.

Use a doubly linked list when you need O(1) deletion with a direct node reference. This is the secret to the LRU cache.

An LRU cache needs:

  • O(1) lookup.
  • O(1) insertion.
  • O(1) eviction.
  • O(1) promotion.

An array cannot do this because moving items requires shifting everything else. A hash map alone cannot do this because it has no order.

The solution is a combination. A hash map provides the lookup. A doubly linked list maintains the order. The hash map stores the node reference. When you access a key, you pull the node directly from the list and move it to the front. No searching. No shifting.

Stop learning data structures just to pass interviews. Learn them to understand how software interacts with hardware.

Source: https://dev.to/islamhafez0/you-dont-use-linked-lists-but-theyre-running-half-your-software-4b37