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 ListSearching 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
- Start current at head (or tail, if searching backward).
- While current is not null, compare current's value with the target.
- If it matches, return current (found).
- Otherwise move to current.next (or current.prev) and repeat.
Search Worked Example
Input: Search for 10 in null <- 5 <-> 10 <-> 15 -> null
- current = 5, no match
- current = 10, match found!
Output: Found at the 2nd node
Press ▶ Run to watch it step by step.
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]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
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
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.