Data Structures · Visualization

Linked List: Traverse

Linked List

Traversing means visiting every node in the list, one at a time, starting from the head and following each 'next' pointer until reaching the end (null). Time: O(n). Space: O(1).

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

Linked List: Traverse

Linked List

Traversing means visiting every node in the list, one at a time, starting from the head and following each 'next' pointer until reaching the end (null). It is the most basic operation because almost every other linked list algorithm is built on top of it.

How Traverse Works

  1. Start a pointer, current, at the head of the list.
  2. While current is not null, process (read/print) current's value.
  3. Move current forward: current = current.next.
  4. Stop when current becomes null — you've reached the end.

Traverse Worked Example

Input: head -> 5 -> 10 -> 15 -> null

  1. current = head (5) → visit 5
  2. current = current.next (10) → visit 10
  3. current = current.next (15) → visit 15
  4. current = current.next (null) → stop

Output: Visited in order: 5, 10, 15

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: traverse on [5, 10, 15]
Input: head -> 5 -> 10 -> 15 -> 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.

Traverse Time & Space Complexity

TimeO(n)
SpaceO(1)

When to Use Traverse

  • Printing or processing every element in a list
  • Searching, summing, or validating list contents
  • The foundation for almost every other linked list operation

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.