# Linear Search in Data Structure

Mentor: Shailendra Chauhan
Duration : 00:02:00

## What is a Linear Search in Data Structure?

The simplest technique for finding an element in a data collection is to use a linear search. It checks each element until it finds a match, from the beginning to the end of the data collection. Once the target element has been found, the search is completed and ended.

## Linear Search Algorithm

• Compare the target to the current element.
• If the values match, return the index and terminate.
• If no match, proceed to the next element.
• Repeat until the target is identified or all components have been verified.

## Linear Search Algorithm's Complexity Analysis

### Space Complexity

The space complexity of linear search is constant, i.e. O(1), because no important additional memory is used.

## When should you use a linear search?

• Small Data Sets: Suitable for small datasets with a few items.
• Unsorted Data: Operates effectively with unsorted or unordered data, checking each element progressively.
• Singly Linked Lists: When direct access is not possible, nodes are traversed one at a time.
• Infrequent Searches: Ideal for infrequent searches or static lists; easy to implement with minimum setup.
• Educational Purposes: Basic search concepts are presented using an introductory algorithm in programming and computer science courses.

• Simplicity
• Efficient for small data sets
• Memory efficiency
• Flexibility