DSA and problem solving

Stage 2 · Lesson 2 of 6

Singly and doubly linked lists

Arrays, hashing, linked lists, stacks and queues

A stores each item in its own node, and each node points to the next one, like a trail of clues where each tells you where the next is. In a singly linked list the nodes only point forward. In a each node also points back to the previous one.

Inserting or removing a node you already hold is O(1), because nothing has to shift. But reaching the i-th item means walking from the start (the head), which is O(n). You will rarely pick one over a , but they matter for two reasons.

They are the building block of other structures, such as and the chains inside hash maps. And pointer problems, like reversing, merging or finding the middle, are the best practice there is for careful code. A , a fake first node before the real ones, removes most edge cases.

A question to check yourself, an AI practice session and 3 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

Keep handy

  • Array, Map and Set pages: what each method does and when a Map beats a plain object

Also worth your time

Mark this stage as not done?