I dont understand 2 and 4

why in 2 complexity is linear

Paste the question here, in which you aren’t able to understand.

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

  1. Output is 20 and time complexity is Linear in size of the list.
  2. Output is 1 and time complexity is Linear in size of the list.
  3. Output is 20 and time complexity is Logarithmic in size of the list.
  4. Output is 1 and time complexity is Logarithmic in size of the list.

Then answer will be option 2 as myList is not an array, it’s a linked list. If you are not familiar with linked list then there will be a section of linked list in your course. When you will do that you will be able to find out why is it option 2.

What is the data type that should be returned by a comparator? If we would like to see item1 before item2 in our final sorted ordering then compare(item1, item2) should return what value? bool and 0 int and any positive number bool and 1 int and any number but 0.

bool and 1, is the answer because return type of comp function is bool and for ascending values, item 1 should be less than item 2, (assuming that item1 occurs before item2) this is why item1 < item2 returns true.

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.