All of the questions refer to this procedure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int find_em(const vector <int> &r,
const map <int, int> &p,
int n)
{
int found;
int i, index;
found = 0;
for (i = 0; i < n; i++) {
index = rand() % r.size();
if (p.find(r[index]) != p.end()) found++;
}
return found;
}
Question 1: Assume that the size of $r$ is $o$, and the size of $p$ is $m$. What is the running time of this function? Please choose from the following multiple choice answers:
A. $O(m \ log(m))$
B. $O(m \ log(n))$
C. $O(m \ log(o))$
D. $O(n \ log(m))$
E. $O(n \ log(n))$
F. $O(n \ log(o))$
G. $O(o \ log(m))$
H. $O(o \ log(n))$
I. $O(o \ log(o))$
find()
operation is $O(log(m))$. So the answer is D: $O(n \; log(m))$.
Question 2: Now assume that the size of $r$ is $m$, and that the size of $p$ is $m/2$. When I run this procedure with $n$ = $10,000,000$ and $m$ = $1,000$, it takes $2.8$ seconds to run. Roughly how long will it take when $n$ = $20,000,000$ and $m$ = $1,000$? (The units will be “seconds”).
Question 3: Given the same assumptions as in Question 2, roughly how long will it take when $n$ = $10,000,000$ and $m$ = $2,000$?