plz explain the concepts of these ques q3,6,7,8,9
About the vector quiz
Hi, can you please mention the questions here and I will help you understand the concept
actually I have screenshots of ques how can I send them to you?
u can paste them here
plz tell if you got them
for Q3 consider vector as array and find time complexity of the recursive funtion, it runs n times once each for each call of i which goes from 0 to n-1
q6 swap function simply changes the pointers v1 and v2 which are pointers to the first element of the vector and is done in O(1) time
q7 it is a vector of pair<int, int> where first int stores the values of arr[i and second stores their index in the original array so when u sort this array according to the values the second will not change and give their original indices
q9 option a is a 2d matrix where u can store 0 if not linked and 1 if linked for each i as the value and j also as values
for eg, consider
0 0 1
0 0 1
1 1 0
it means 1->3, 2->3, 3->1, 2 because of 1
option 2 is same just with boolean values and indices will remain same
option 3 is n vectors of vectors
1,2->2,3 it will store values in this way, like a 3d matrix
q9 since intially int of size 1000 is defined it will go to else for first 1000 calls but after that it will create a new space of size capacity +1 and repopulate the array and hence o(n)
Im unable to understand q3 and 9
In q7 we will have to make our own comparator in order to sort acc to values
for q3: do this small excercise, make a recursion tree, consider i=0
it goes in function there are no loops so it is o(1) execution then it calls for i=1 which is again o(1)
so on it goes upto some size of the vector let us say 5 for example so it is 5 calls of o(1) which means if o(1) was taking 1 second this will take 5 seconds, so for n size it will take n seconds hence total complexity is o(n)
for q9: do not worry if u are not familiar with graphs now, u will eventually understand the representation of the graph once u come to it, then u will be able to understand it better
q7: it can be done through stl as well, and you do not need 2 arrays in any case at all
thank you for clearing my doubt




