Computers and Technology

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?

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 17:00, DRock4976
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
image
Computers and Technology, 22.06.2019 21:30, aesthetickait
How do you take a green screen out of the video while editing?
Answers: 2
image
Computers and Technology, 23.06.2019 22:20, kandi2565
What is a programming method that provides for interactive modules to a website?
Answers: 1
image
Computers and Technology, 24.06.2019 01:00, arturocarmena10
The initial tableau of a linear programming problem is given. use the simplex method to solve it. x 1 x 2 x 3 s 1 s 2 z 1 2 4 1 0 0 8 3 4 1 0 1 0 10 minus3 minus12 1 0 0 1 0 the maximum is nothing when x 1equals nothing, x 2equals nothing, x 3equals nothing, s 1equals3, and s 2equals0. (be sure to simplify to lowest terms if necessary.)
Answers: 2
Do you know the correct answer?
Suppose you have two vector of integers x and y, each of which have N randomly distributed but disti...

Questions in other subjects:

Konu
Biology, 04.04.2020 18:14
Konu
Mathematics, 04.04.2020 18:14