Oh My Algorithm
Algorithm Guidecomplexity: Insert O(1) · Search O(n)

Linked List

A structure where each node holds a value and a pointer to the next node. It needs no contiguous memory, so insertion and deletion are O(1), but random access is O(n) and must be traversed sequentially.

01Linked List

Starting the linked list. head points to nothing yet (empty list).

push_front(10) · Create a new node 10 and point head at it.

push_front(24) · Link the new node 24's next to the old head (10), then move head to 24.

push_front(37) · Attach 37 at the front the same way. Just rewire the pointers — O(1).

find(24) · Follow from head. The first node 37 isn't 24, so move to next.

The next node 24 matches the target — return it.

Front insertion is O(1) since it only rewires pointers, but searching for a value is O(n), walking from head in order.

head∅ null
1 / 7

02 Understand It Simply

For Everyone
🔑How It Works

Each node carries a value plus the address of the next one. The nodes need not sit next to each other, but reaching the nth requires walking from the front.

💡In Plain Words

Each piece of data carries an 'arrow to the next one'.

Fixing just the arrows makes middle insertion and deletion easy (random access is slow).

📍Where It's Used
  • Music playlists
  • photo slideshows
  • when memory must be used piecemeal

03 Python Implementation

A clean, readable reference implementation of the core logic of Linked List.

core_implementation.py
class Node:
    def __init__(self, value):
        self.value = value
        self.next = None

class LinkedList:
    def __init__(self):
        self.head = None

    def push_front(self, value):
        node = Node(value)
        node.next = self.head
        self.head = node

    def find(self, value):
        cur = self.head
        while cur:
            if cur.value == value:
                return cur
            cur = cur.next
        return None

04 Frequently Asked Questions

FAQ
What is Linked List?+

A structure where each node holds a value and a pointer to the next node. It needs no contiguous memory, so insertion and deletion are O(1), but random access is O(n) and must be traversed sequentially.

What is the time complexity of Linked List?+

The time complexity of Linked List is Insert O(1) · Search O(n). Follow the step-by-step visualization to see exactly why.

Where is Linked List used?+

Music playlists, photo slideshows, when memory must be used piecemeal.

What's a simple analogy for Linked List?+

Each node carries a value plus the address of the next one. The nodes need not sit next to each other, but reaching the nth requires walking from the front.