r/computerscience • u/Obi_Wan_06 • Sep 24 '25
does sequential search compare every element even if there is an absence?
like for example we have this list (1,5,17,40,92,100) and i want to see how many comparisons will it do to understand that the number 35 for example is missing. will it stop at 40 or will it go till the end of the list?
1
Upvotes
View all comments
Show parent comment
8
u/O_xD Sep 24 '25
Worth noting, if you require that the list is sorted, you can do a more efficient search, for example check 40, 5, 17, and conclude its not there in O(log(n)) time.
Your point stands though, sequential search is always O(n)