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

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 07:50
Apython programming question: assume s is a string of lower case characters. write a program that prints the number of times the string 'bob' occurs in s. for example, if s = 'azcbobobegghakl', then your program should print number of times bob occurs is: 2
Answers: 3
question
Computers and Technology, 23.06.2019 15:00
Idon’t understand the double8 coding problem. it is java
Answers: 1
question
Computers and Technology, 23.06.2019 21:30
Examine the list below. which factors positively affect lifetime income? check all that apply.
Answers: 1
question
Computers and Technology, 24.06.2019 00:40
What social factors affect your health
Answers: 3
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
question
Mathematics, 04.12.2020 02:00
question
Mathematics, 04.12.2020 02:00
question
Health, 04.12.2020 02:00
question
Mathematics, 04.12.2020 02:00
question
Mathematics, 04.12.2020 02:00
Questions on the website: 13722360