Home / DSA / Lesson 5

Linked lists

Intermediate 9 min read Lesson 5 of 9

A singly linked list is nodes: value + next. You do not have O(1) index access; you walk from the head. Insert or delete is O(1) if you already hold the previous node.

Reverse: keep prev, cur, next. Point cur.next = prev, then slide. Draw it; do not do it only in your head.

Fast/slow pointers (Floyd): slow moves 1, fast moves 2. If they meet, there is a cycle. Mid of an even/odd list: when fast hits the end, slow is in the middle.

Judge: Reverse list. Pattern: List reversal, Fast & slow.