Linked List
Software Engineer path · lesson 3 of 99A linear data structure where elements are not stored at contiguous memory locations. The elements are linked using pointers.
Syntax: inserthead n · inserttail n · search n · delete n · reverse. Numbers from -99 to 99.
head → null
Empty list: head is null.
- 1insertHead(x): n = Node(x); n.next = head; head = n # O(1)
- 2insertTail(x): walk to the last node; last.next = Node(x) # O(n)
- 3search(x): cur = head; while cur and cur.val != x: cur = cur.next
- 4delete(x): find prev of x; prev.next = x.next # unlink
- 5reverse(): prev = None; while cur: nxt = cur.next; cur.next = prev; prev, cur = cur, nxt
- Pointer hops
- 0 / 6
- Pointer writes
- 0 / 6
Tap any element in the diagram to inspect its state at this step.
Keys: ← → step, Space play/pause. Predict mode pauses before key steps and asks what happens next.
Reverse a singly linked list
Order one iteration of the three-pointer reversal, from set-up to finish.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
Test your knowledge
What is the time complexity to access the Nth element?
The short version
Think of a treasure hunt where each clue tells you exactly where to find the next clue. You can't skip ahead; you must follow the chain. Unlike a bookshelf (Array) where you can grab the 5th book instantly.
In more depth
Dynamic Chains
A Linked List is a linear data structure where elements are not stored in contiguous memory locations. Instead, each element (node) points to the next.
Pros vs Arrays:
Cons:
Tortoise and Hare:
A classic technique for Linked Lists is using two pointers moving at different speeds to detect cycles or find the middle element.
When to reach for this
- When size is unknown or changes frequently
- When you need constant time Insert/Delete at the start
- Implementing Stacks or Queues
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required