Doubt regarding quiz

explanation for 2,6,10

@shashank3256 hey please send me all three questions here.I will help you.

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.

Given the following code snippet :

bool comp(string s1, string s2)
{
if(s1.length() < s2.length())
return 1;
else if(s1.length() > s2.length())
return 0;
else return s1 < s2;
}

vector< string > data = {“b”, “a”, “c”, “abc”, “bca”, “xy”};
sort(data.begin(), data.end(), comp);
for(string item : data)
cout << item << " ";

Choose the correct output :

a b c abc bca xy

xy bca abc c b a

a b c xy abc bca

b a c xy abc bca

@shashank3256 hey ,in first question binary search is logn in complexity and return true if element is found so ans will be :Output is 1 and time complexity is Logarithmic in size of the list.
In 2nd question output will be:
a b c xy abc bca
Comparator function is type se sorting krrha hai ki jiski length choti hai wobh pehle ayega ,agar dono ki brabar hai to lexographicallly order me jo chota hai woh pehle ayega
Hope you get it.

1 Like

image

it says 2nd option is correct, thats why i asked

@shashank3256 hn iska answer galat tha,don’t worry.

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.