[Verse 1]
Started with a problem, need to find my data
Got an array sitting there, elements scattered
Linear search the method, going step by step
Check each position till I find what I kept
From index zero, that's where we begin
Compare each element, looking for the win
If it matches what I'm searching, then we're done
Return the index where the target was found
[Chorus]
One by one, check them all
Linear search will never fall
Start to end, don't skip a beat
O of n, the time complete
One by one, through the line
Linear search works every time
Found or not, we'll know for sure
Simple algorithm, clean and pure
[Verse 2]
Time complexity linear, that's the cost we pay
If the array's got n elements, n checks max we'll weigh
Best case scenario, target's at the front
One comparison and we're done, that's what we want
Worst case different, target's at the end
Or maybe not there, through the whole we'll wend
Average case analysis, halfway through we'll find
N over two comparisons, keep that in mind
[Chorus]
One by one, check them all
Linear search will never fall
Start to end, don't skip a beat
O of n, the time complete
One by one, through the line
Linear search works every time
Found or not, we'll know for sure
Simple algorithm, clean and pure
[Bridge]
No sorting needed, works on any list
Unsorted data, nothing will be missed
Sequential access, memory friendly too
Cache locality, performance coming through
Return the index if the element's there
Minus one or null if it's nowhere
Sentinel values, mark the search complete
Linear scan approach, can't be beat
[Verse 3]
Implementation simple, loop structure clean
For or while statement, either fits the scene
Iterator pattern, modern languages shine
Functional approach, filter and find
Early termination when the match is made
No need to continue, efficiency's displayed
Boolean version, just return true false
Or custom predicate, however you want to solve
[Chorus]
One by one, check them all
Linear search will never fall
Start to end, don't skip a beat
O of n, the time complete
One by one, through the line
Linear search works every time
Found or not, we'll know for sure
Simple algorithm, clean and pure
[Outro]
When binary search can't help you out
Linear's got you covered without a doubt
Foundation algorithm, learn it well
Sequential searching, time will tell