Computers and Technology, 03.12.2019 05:31 leximae2186
**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?
Answers: 2
Computers and Technology, 22.06.2019 02:30
The can be used to paste text in any order
Answers: 1
Computers and Technology, 22.06.2019 11:00
How does a policy manual an organization? a. it boost productivity. b. it create awareness in employees about the organization’s values. c. it employees achieve targets. d. it safeguards the organization from liabilities.
Answers: 1
Computers and Technology, 23.06.2019 04:00
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
Answers: 3
Computers and Technology, 23.06.2019 04:31
Type the correct answer in the box. spell all words correctly. the managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an
Answers: 1
**c++ question**
suppose you have two vector of integers x and y, each of which have n...
suppose you have two vector of integers x and y, each of which have n...
Mathematics, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57
Physics, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57
Spanish, 04.02.2020 14:57
Computers and Technology, 04.02.2020 14:57
Mathematics, 04.02.2020 14:57