Hello Glorious Day,

that is an eligible question. In my experience it is almost never necessary to create a low level data structure like a linked list in a common frontend web application. I encourage you to prefer arrays with their build-in methods over a custom linked list in all situations where performance is not a critical factor. In other words: try the approach with the higher readability first and only if you get performance issues, think about ways to improve performance.

However, typical coding interview questions tend to include classical low level data structures like linked lists and in many languages there are implementations of these in the standard libraries. Since JavaScript is relatively new as an interviewing language, the old questions are to be solved with JavaScript. I suggest to ask your interviewer if you can use arrays and point out that you are aware about the differences in asymptotic runtime complexity. Then you don’t have to build your own linked list during an interview but the interviewer can see that you know about them.

If arrays and objects are faster to store and retrieve data from depends on the situation. I.e. if your data has an order and you need to store something at a specific position in that order, that can be done in O(1) in a linked list, whenever you hold a reference to the previous element. To do that with an array would take O(n) because you have to shift all following elements by 1. The same holds for removing elements. Whenever you find yourself in a situation like this and you suffer performance issues, you should consider to use a linked list.

Linked lists do not imply mutability in general, even though the simple implementation that I show in the article includes mutability of the structure itself. The data that is stored in a node of a linked list can be immutable and whenever you update it you can create a fresh object.

There are also implementations of immutable linked lists: https://stackoverflow.com/questions/10045446/efficient-implementation-of-immutable-double-linkedlist

Software Engineer 🚀 JavaScript 👾 TypeScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store