Linear Search
Linear Search sequentially checks each element in the array until it finds the target or reaches the end.
BeginnerTime: O(n)Space: O(1)
Take QuizCurrent Step
Press Play to start the visualization
## How Linear Search Works
Linear Search is the simplest searching algorithm. It sequentially checks each element of the array until a match is found or the end is reached.
### Algorithm Steps:
1. Start from the first element
2. Compare current element with the target
3. If match found, return the index
4. If not, move to the next element
5. Repeat until found or end of array
### Key Characteristics:
- **Simple**: Easy to implement and understand
- **No prerequisites**: Works on unsorted arrays
- **Sequential**: Checks elements one by one
Time & Space Complexity
| Case | Time Complexity |
|---|---|
| Best | O(1) |
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
Practice Problems
10 problems81 total points
1
Find First Occurrence
Beginner5 pts
2
Count Occurrences
Beginner5 pts
3
Find Maximum Element
Beginner5 pts
4
Find All Indices
Intermediate8 pts
5
Find Second Largest
Intermediate8 pts
6
Find Missing Number
Advanced10 pts
7
Find Peak Element
Advanced10 pts
8
Majority Element
Advanced10 pts
9
Find Duplicate Number
Advanced10 pts
10
First Missing Positive
Advanced10 pts