Linear Search
What is Linear Search?
Linear search is a search algorithm that searches for a target value in a collection of elements by iterating through each element in the collection until the target value is found or the end of the collection is reached.
How to implement Linear Search?
To implement linear search, we need to iterate through each element in the collection until the target value is found or the end of the collection is reached.
Example
Let's search for the target value 3 in the collection [1, 2, 3, 4, 5] using linear search.
First, we need to iterate through each element in the collection until the target value is found or the end of the collection is reached.
Element | Target Value | Is Found |
---|---|---|
1 | 3 | No |
2 | 3 | No |
3 | 3 | Yes |
The target value 3 is found in the collection [1, 2, 3, 4, 5].
Become a Sponsor![Heart with ribbon](/_next/image?url=%2Fheart-with-ribbon.png&w=48&q=75)
Become a sponsor and help us maintain and improve this project. Every contribution counts. Thank you!