Linear search

hip-hop, educational · 2:49

Listen on 93

Lyrics

[Verse 1]
Starting from the top with my array in hand
Got a target value that I need to understand
Check position zero is it what I seek
If it matches then my search is complete
But if not then I move to the next spot
One by one till I find what I got
Sequential scanning through each memory slot
Linear search baby this is how we rock

[Chorus]
One by one check every single one
Start to finish till the job is done
O of n that's the time we need
Linear search is guaranteed
First to last we never skip ahead
Check each element till we find what we said
One by one check every single one
Linear search until the job is done

[Verse 2]
Worst case scenario target's at the end
Or maybe not there gotta check again
Best case lucky it's the very first
Average case halfway through the list we traverse
No assumptions bout the data structure
Unsorted arrays this is what we nurture
Simple algorithm easy to code
Step by step down the linear road

[Chorus]
One by one check every single one
Start to finish till the job is done
O of n that's the time we need
Linear search is guaranteed
First to last we never skip ahead
Check each element till we find what we said
One by one check every single one
Linear search until the job is done

[Bridge]
When the data's all scrambled no order in sight
Linear search gonna treat you right
Binary search needs that sorted flow
But linear works wherever you go
Initialize index start at zero
Loop through positions be the hero
Compare and contrast till you find your match
Linear search got your back

[Verse 3]
For loop running while the index is small
Check if current equals target call
If condition true return the spot
If not increment give it another shot
When you reach the end and nothing's found
Return negative one or false profound
Simple logic but it gets things done
Linear search for everyone

[Chorus]
One by one check every single one
Start to finish till the job is done
O of n that's the time we need
Linear search is guaranteed
First to last we never skip ahead
Check each element till we find what we said
One by one check every single one
Linear search until the job is done

[Outro]
From arrays to lists it never fails
Sequential search always prevails
Linear time complexity
That's the algorithmic key
One by one we check them all
Linear search standing tall

← Binary search | Interpolation search →