Linked lists are data structures containing nodes that have a value and a reference to the next (and previous) node.

Compared to arrays, the complexity of dynamic insertion and deletion is constant time, there is no need to shift the indices when modifying the list. (If reaching the desired node is included here, obviously it’s O(n)).

In a singly linked list, each node points only to the next one, so you can traverse the list in a single direction forward. If you lose reference to a previous node, you cannot access it again.

TIP

When implementing the linked lists via code, separate the traversals and the mutations. Makes it cleaner.

When solving problems involving linked lists, some of them used a dummy node pattern (creating a new node entirely) and others - pointers to previous values, for example.

Using a dummy comes in handy when we modify or delete the head of the list. So when we’d catch ourselves writing if (prev === null) etc.

Examples of problems using a dummy: removing elements from a given list that match a given value, merging lists, removing the Nth node

Examples of problems using pointers: reversing a linked list (use one next and prev pointer), remove duplicates in a list, checking whether we have a cycle (use pointers for slow and fast)