subject

Suppose you have two vector of integers x and y, each of which have N randomly distributed but distinctvalues. We want to merge x and y into a third vector z such that z has all the integers of x and y, additionally z should not have any duplicate values. For this problem we are not concerned with orderingin any of these vectors. a. Here is one algorithm. What is the Big-O of this algorithm?void merge1(const vector& x, const vector& y, vector& z) {z. clear();z. reserve(x. size() + y. size());for (int i = 0; i < x. size(); ++i)z. push_back(x[i]);for (int j = 0; j < y. size(); ++j) {bool duplicate = false;for (int i = 0; i < x. size(); ++i) {if (y[j] == x[i]) {duplicate = true;break;}}if (!duplicate)z. push_back(y[j]);}}b. Here is another algorithm that uses a sorting function, assume that the sort function is implemented asquicksort. What is this algorithm’s Big-O?void merge2(const vector& x, const vector& y, vector& z) {z. clear();z. reserve(x. size() + y. size());for (int i = 0; i < x. size(); i++)z. push_back(x[i]);for (int j = 0; j < y. size(); j++)z. push_back(y[j]);sort(z. begin(), z. end());int last = 0;for (int k = 1; k < z. size(); k++) {if (z[last] != z[k]) {last++;z[last] = z[k];}}z. resize(last + 1);}c. Which algorithm performs better given the provided description of inputs?d. Suppose the input vectors are:vector x{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 15,16,17,18,19,20};vector y{21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39};How will that change your analysis done in the previous parts?

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:30, relic7391
Is a string of code written to hurt others by damaging or destroying
Answers: 1
image
Computers and Technology, 22.06.2019 10:10, joanasprinkman2262
3. bob is arguing that if you use output feedback (ofb) mode twice in a row to encrypt a long message, m, using the same key each time, it will be more secure. explain why bob is wrong, no matter what encryption algorithm he is using for block encryption (15 points).
Answers: 3
image
Computers and Technology, 22.06.2019 16:30, mesposito
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
image
Computers and Technology, 22.06.2019 17:50, ImBADatmath8743
Farah works in an office with two other employees. all three share a printer and an internet connection. the utility that makes this possible is defragger quicktime soho winzip
Answers: 1
You know the right answer?
Suppose you have two vector of integers x and y, each of which have N randomly distributed but disti...

Questions in other subjects: