Data Structures · Visualization

Doubly LL: Traverse

Doubly Linked List

Traversing a doubly linked list works like a singly linked list, but it can go in either direction: forward from head using 'next', or backward from tail using 'prev'. Time: O(n). Space: O(1).

Big-O: Insert/delete at either end O(1); extra memory for prev pointers.

Doubly LL: Traverse

Doubly Linked List

Traversing a doubly linked list works like a singly linked list, but it can go in either direction: forward from head using 'next', or backward from tail using 'prev'. This flexibility is the main advantage over a singly linked list.

How Traverse Works

  1. To go forward: start at head, follow 'next' until reaching null.
  2. To go backward: start at tail, follow 'prev' until reaching null.
  3. Process (read/print) each node's value as you visit it.

Traverse Worked Example

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

  1. Forward from head: visit 5, 10, 15
  2. Backward from tail: visit 15, 10, 5

Output: Forward: 5, 10, 15 | Backward: 15, 10, 5

Try your own input
Doubly LL: Introduction
Like a linked list, but every node keeps a pointer to both the previous and the next node, so you can walk it in either direction.
head
17
prev · next
30
prev · next
43
prev · next
56
prev · next
tail
69
prev · next
Active node next pointer prev pointer
Doubly LL: Introduction
Press ▶ Run to watch it step by step.
Python · Doubly 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: null <- 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

  • Displaying a playlist forward or in reverse
  • Scrolling browser history both backward and forward
  • Any feature needing bidirectional iteration

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.