Data Structures · Visualization

Doubly LL: Search

Doubly Linked List

Searching a doubly linked list checks each node's value in sequence until a match is found, just like a singly linked list. Time: O(n). Space: O(1).

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

Doubly LL: Search

Doubly Linked List

Searching a doubly linked list checks each node's value in sequence until a match is found, just like a singly linked list. The two-way links do not speed up a single search, but they do let you search from whichever end is more convenient, or from a known node outward in both directions.

How Search Works

  1. Start current at head (or tail, if searching backward).
  2. While current is not null, compare current's value with the target.
  3. If it matches, return current (found).
  4. Otherwise move to current.next (or current.prev) and repeat.

Search Worked Example

Input: Search for 10 in null <- 5 <-> 10 <-> 15 -> null

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

Output: Found at the 2nd node

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: search 10 on [5, 10, 15]
Input: Search for 10 in 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.

Search Time & Space Complexity

TimeO(n)
SpaceO(1)

When to Use Search

  • Checking if an item exists before inserting/removing it
  • Looking up a cache entry by key in a manual implementation
  • Validating list contents in small structures

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.