Q2. Algorithms STL#2

the question is: 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) ;

query: why answer of time complexity is Linear in size of the list but not Logarithmic.

std::list iterators are not random-access-iterators (they are forward-iterators), so the complexity is O(n).

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.