Data Structures · Visualization

Linked List: Search

Linked List

Searching means walking the list from the head, checking each node's value one by one, until you either find a match or run out of nodes. Time: O(n). Space: O(1).

Big-O: Lookup O(n); insert/delete at head O(1).

Linked List: Search

Linked List

Searching means walking the list from the head, checking each node's value one by one, until you either find a match or run out of nodes. Unlike an array, you cannot jump to a middle node, so every search must move step by step through the links.

How Search Works

  1. Start a pointer, current, at the head.
  2. While current is not null, check if current's value matches the target.
  3. If it matches, return that node (found).
  4. Otherwise move current to current.next and repeat.
  5. If current becomes null, the value was not in the list.

Search Worked Example

Input: Search for 15 in head -> 5 -> 10 -> 15 -> 20 -> null

  1. current = 5, no match
  2. current = 10, no match
  3. current = 15, match found!

Output: Found at the 3rd node

Try your own input
Linked List: Introduction
A chain of nodes, each holding a value plus a pointer to the next node — unlike an array, the values are not stored side by side in memory.
12
99
37
5
71
∅
Active / pointers Result null (end) Random pointer
Linked List: Introduction
Press ▶ Run to watch it step by step.
Python · Singly Linked List in Code
def traverse(head):
    cur = head
    while cur:
        print(cur.val, end=" -> ")
        cur = cur.next      # follow next pointer
    print("None")
# example: search 15 on [5, 10, 15, 20]
Input: Search for 15 in head -> 5 -> 10 -> 15 -> 20 -> null

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Search Time & Space Complexity

TimeO(n)
SpaceO(1)

When to Use Search

  • Checking whether an item exists before inserting or deleting it
  • Looking up a record by ID in a simple linked structure
  • Validating membership in small or moderately sized lists

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.