PyDSAWHY Engine
Back to Roadmap
Track 08 of 10
Data StructuresIntermediate Level~25 Mins

8. Singly & Doubly Linked Lists

Understand node pointers, head references, traversal, insertion, and list reversal.

The "WHY" Core Principle

Arrays require contiguous memory blocks. Linked lists store disconnected Node objects on the Heap.

Interactive Visualizer

Stack (LIFO) & Queue (FIFO) Interactive Simulator

Observe the difference between Last-In First-Out (Stack) and First-In First-Out (Queue).

val: 10
val: 20
val: 30TOP

Interactive Code Snippets (1 Lessons)

Lesson 01

Reverse a Singly Linked List In-Place

O(N)O(1)

Reverse all node `.next` pointers in O(N) time and O(1) auxiliary space.

WHY Under The Hood:

Maintain three pointers: `prev`, `curr`, and `next_node`. Update `curr.next = prev` at each step.

CPython C Struct Detail: Reversing pointers modifies PyObject reference attributes in place.

Reverse a Singly Linked List In-Place

Pyodide WASM Engine

Type, edit code, and click 'Run & Profile' to see live runtime ms and operation count!

Python 3.12 Code (Editable)
Expected:Time: O(N)Space: O(1)

Test Your Understanding

WHY does inserting an element at index 0 take O(1) in a Linked List but O(N) in a Python list?