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 18:30
The computers in the sales department did not have enough data storage capacity to contain all the information the department needed to store, and it was taking a long time for team members to access the data they needed. to fix the problem, the technician installed new, larger hard drives on all the computers.
Answers: 1
question
Computers and Technology, 24.06.2019 16:00
Read these lines from beowulf.often scyld scefing seized mead-benches from enemytroops, from many a clan, he terrified warriors, even thoughfirst he was found a waif, best explains why the author includes this information in theexposition? a. to emphasize that a hero must learn to be fierceb. to remember the famous story of a popular heroc. to express sadness about losing the old heroesd. to see whether people still respect the old heroes
Answers: 1
question
Computers and Technology, 24.06.2019 19:00
Which of the following "invisible" marks represents an inserted tab?
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, 21.08.2019 15:50
question
Mathematics, 21.08.2019 15:50
question
Mathematics, 21.08.2019 15:50
Questions on the website: 13722367