Skip to content

Linked List

Medium — good to knowGeneral Dev

ELI5 — The Vibe Check

A linked list is like a treasure hunt where each clue tells you where the next clue is. Each item (node) holds a value AND a pointer to the next item. Unlike arrays, items are not side-by-side in memory — they are scattered around, connected by pointers. Great for inserting items in the middle, terrible for random access.

Real Talk

A linked list is a linear data structure where each node contains data and a reference (pointer) to the next node. Unlike arrays, nodes are not stored contiguously in memory. Linked lists provide O(1) insertion and deletion at the head, but O(n) access by index. Doubly linked lists also store a pointer to the previous node, enabling traversal in both directions.

Show Me The Code

// Implementing a simple linked list in JS:
class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class LinkedList {
  constructor() { this.head = null; }
  prepend(value) {
    const node = new Node(value);
    node.next = this.head;
    this.head = node; // O(1)
  }
}

// head → [1] → [2] → [3] → null

When You'll Hear This

"Linked lists are great for queues where you insert and delete from both ends." / "Arrays are usually better unless you need O(1) insertion in the middle."

Made with passive-aggressive love by manoga.digital. Powered by Claude.