subject

**c++ question**

suppose you have two vector of integers x and y, each of which have n randomly distributed but distinct
values. 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 ordering
in 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.;
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 as
quicksort. what is this algorithm’s big-o?
void merge2(const vector& x, const vector& y, vector& z) {
z. clear();
z. reserve(x. size() + y.;
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. z.;
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, 22.06.2019 19:00
Which parts of a presentation should be the most general? a. introduction and conclusion b. introduction and outline c. outline and conclusion d. outline and body
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Select the correct answer from each drop-down menu. which types of computer networks are bigger as well as smaller than a man? a man is a network of computers that covers an area bigger than a , but smaller than a .
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 24.06.2019 00:00
Afashion designer wants to increase awareness about her brand. which network can she use and why she can use the blank to blank her products online. answers for the first blank: internet, extranet, or intranet answers for the second blank: market, design, and export
Answers: 1
You know the right answer?
**c++ question**

suppose you have two vector of integers x and y, each of which have n...
Questions
question
Mathematics, 02.03.2021 14:00
question
Mathematics, 02.03.2021 14:00
question
Mathematics, 02.03.2021 14:00
question
Computers and Technology, 02.03.2021 14:00
question
Chemistry, 02.03.2021 14:00
question
English, 02.03.2021 14:00
question
Computers and Technology, 02.03.2021 14:00