Binary_search STL time complexity

Choose the correct output and time complexity for the following code :

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

a-Output is 20 and time complexity is Linear in size of the list.

b-Output is 1 and time complexity is Linear in size of the list.

c-Output is 20 and time complexity is Logarithmic in size of the list.

d-Output is 1 and time complexity is Logarithmic in size of the list.

Answer should be (d) but it is given (b) , right?

@ashish_meher
hello ashish,
you are given list( which is linked list) and to find mid element you need to traverse half list that why b is correct

1 Like

Thank you. I understood.

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.