Please explain q2

Q2. Algorithms STL#2
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) ;
Output is 20 and time complexity is Linear in size of the list.

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

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

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

this is because of linked list
in binary search
to find mid we have to traverse the LL hence time complexity of finding mid is O(n) as well
hence overall time complexity is also O(n)

how the output is 1 and does list is the keyword for inbuilt linked list

binary search function returns 1 if it found the element otherwise 0

Yes List is STL used for Linked List

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.