Introduction

Searching in a Linked List means finding whether a target value exists in the list.

The task is to:

  • start from head node
  • compare each node value
  • return true if found

Example:

Input:
1 -> 2 -> 3 -> 4
Target:
3
Output:
Found

Explanation:

Traverse nodes one by one.
1 != 3
2 != 3
3 == 3
Element found.

This problem is one of the most important basics of:

Linked List Data Structure 

Constraints

 1 <= Number of Nodes <= 10^5-10^9 <= Node Value <= 10^9

Approach 1 : Brute Force (Convert to Array)

Explanations:

Explanation:

The idea is:

  • convert linked list into array
  • perform linear search in array

Steps:

  1. Traverse linked list.
  2. Store values in array.
  3. Search target value.

This approach works but:

  • uses unnecessary extra space

So direct linked list traversal is preferred.

Dry Run

Input:1 -> 2 -> 3 -> 4

Target:
3
Step 1:
Array:
[1,2,3,4]
Step 2:
Search 3
Element found
Final Output:
Found

Practice :

Complexity Analysis :

Time Complexity:- O(n)
Explanation :

Every node is visited once.
Space Complexity:- O(n)
Explanation :

Extra array is used.

Approach 2 : Optimal Solution(Direct Traversal)

Explanations:

Explanation:

This is the most optimized and interview-preferred solution.

The idea is:

  • traverse linked list directly
  • compare node values one by one
  • stop immediately if target is found

This avoids extra space usage.

Dry Run

Input:1 -> 2 -> 3 -> 4

Target:
3
Step 1:
1 != 3
Move next
Step 2:
2 != 3
Move next
Step 3:
3 == 3
Element Found

Traversal Stops

Practice :

Complexity Analysis :

Time Complexity:- O(n)Explanation :
Each node is visited once.
Space Complexity:- O(1)
Explanation :

No extra space is used.

Why This Problem is Important

This problem builds the foundation for:

  • Linked List traversal
  • Pointer movement
  • Sequential searching
  • Node comparison
  • Dynamic data structures

Real-World Applications

Searching in linked lists is used in:

  • Browser history
  • Playlist traversal
  • Memory management
  • Dynamic scheduling
  • Undo systems

Common Beginner Mistakes

  • Forgetting NULL checks
  • Infinite traversal loops
  • Incorrect target comparison
  • Losing current pointer
  • Not stopping after finding target

Interview Tip

Interviewers often expect:

  • proper linked list traversal
  • correct target comparison
  • O(n) search explanation
  • clean pointer handling

Always explain:

  • why linked lists require sequential access
  • how traversal stops after finding target

Related Questions

  • Traverse Linked List
  • Insert/Delete Node
  • Reverse Linked List
  • Middle of Linked List
  • Detect Cycle in Linked List

Final Takeaway

The Search in Linked List problem is one of the most important beginner linked list problems.

It teaches:

  • pointer traversal
  • sequential searching
  • node comparison
  • linked structure understanding

Understanding this problem builds a strong foundation for:

  • advanced linked list problems
  • pointer manipulation
  • interview-level data structure questions.