In Quiz on STL For Binary Search Question why is complexity Linear

In STL QUIZ Given
int [] s= { 1,1 2,2 ,3 , 3 ,4,4 ,5,5 20 };

cout<<binary_search(s.begin(),s.end(),20)

here ans should be
1 is printed and Time complexity is logarithmic to size of array

but its given linear to size of array .
Is this correct , if so how ? Kindly help

Hey @achin1tya
the answer will be 1(it’ll return bool value) with o(n) complexity only as it’s a linked list so it will take o(n) time to iterate over elements.

1 Like

HI , Thx , i missed the fact that its a list , so thats why even though we applied binary search its still o(n); cool

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.