- how can abc be the last string?
- regarding the complexity
- max_element is not a defined function?
- cant understand how the code is working
- how is compare working
- binary_search has log complexity
Regarding q10,9,8,5,4,2
please check your mail
plz reply to my doubts which I have asked
how can I send you the images. I have been sending them but the delivery fails since 2 days. plz tell me an alternate to this
@aslesha.j7 For Q1. There are two find function in C++, one that is invoked using class object this has time complexity O(long) Another find is a simple function call, it works in O(n) as it is given in answer.
Q 5. The comparator will first place the smaller string in case two strings of equal size it will place the first the lexicographically smaller string.
Q 4. Comp functions place the first argument ahead when value returned is 1.
Q 6 Look up the syntax of pair and typedef, nothing to explain here.
Q 2. List is Linked List (STL) now list does not have random access like array so even binary search will be linear.
Q 7. Inbuilt sort uses a mix of different algorithms instead of 1 algorithm.
Q 8. max_element is an STL Function, no need of defination.
Q 9. reverse makes changes in place, i.e. any change made using reverse are reflected back to passed argument (pass by reference is used)
Q 10. cba is the last permutation of string next permutation will now provide the first permutation.
If this resolves your doubt mark it as resolved.
could you plz tell me how to dry run the q5 as Im not able to
q9 how is it pass by reference? and how is the time complexity seen?
@aslesha.j7 sorry a dry run would be too long and kind of difficult as how the exact code of sort is implemented is not known to me. Just keep the property I mentioned in q4 in mind.
For complexity and other behaviours of STL refer site cppreference.com or cplusplus.com.
There are many stls you need not learn all of them just get an idea of the most basics one , you will learn about rest as you go.
If this resolves your doubt mark it as resolved.
how can I mark it resolved if it is not clear to me
Q5.
vector data = {“b”, “a”,“c”, “abc”,“bca”,“xy”};
we call the bool comparator function
we encounter 3 condition
if(a.length() < b.length()) return true => sort in increasing order if first string is smaller than 2nd
[eg. { b, ab }are sent then then since “b” size is small than “ab”-> value returned in sorted order would be b,ab]
esle if( a.length() > b.length()) return false /// do no sort in decreasing order also increasing order of size
[ eg {abc, b} -> return 0 => sorted in increasing order returns {b,abc}]
return a< b /// sort lexographically
{ executed when both the strings are of same length
dex , ads sent =>. returns in increasing sorted order =>> ads , dex }
so
{“b”, “a”,“c”, “abc”,“bca”,“xy”};
when the elements are sent they are sorted in increasing lexographic order
if they are of same size gives us a b c
then xy abc bca sent
since xy is smaller in length than both abc and bca
so xy is returned first in the sorted order
then
abc then bca
final order
a b c xy abc bca
ans 9
string temp = s ;
reverse( s.begin() , s.end());
return s== temp;
so O(n) space because a temporary string temp is formed so
O(n) time since reverse function has time complexity of O(n )
read the below : it has info reverse function
http://www.cplusplus.com/reference/algorithm/reverse/
thank you for the help
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.









