In ques 2 algo stl quiz

why is answer 1 here also complexity should hve been logarithmic but it is showing linear pls tell

Hey @sneha23, can you please elaborate your doubt. I can’t understand what you are saying.

list< int > myList = { 2, 6, 12, 13, 15, 18, 20};
cout << binary_search(myList.begin(), myList.end(), 20) ;

Isn’t this algorithm logarithmic in this case?
why is answer 1 here also complexity should hve been logarithmic but it is showing linear pls tell

Hey @sneha23 the answer will be 1 with o(n) complexity only as it’s a linked list so it will take o(n) time to iterate over elements. Hope this would help :slight_smile:

coud u pls tell why 1 will be returned

is it smthing like if element is present it returns 1 are if not 0???

Exactly @sneha23 you got it right, it return bool value i.e., 0 or 1 .

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.