Clickers Flashcards

1
Q

Assuming open addressing, what is the running time of inserting an element into a hash table with n elements and a load factor of 0.5

A

When half the table is empty, expected number of probes to find an empty slot is 2, so O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Assuming open addressing, what is the running time of inserting an element into a hash table with n elements and only 10 empty slots

A

With only 10 empty slots, expected probes becomes n/10, so O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Assuming seperate chaining, what is the running time of inserting an element into a hash table with n elements and a load factor of f

A

With a load factor of f, the average size of a vector in the table is f, so the answer is O(f)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the running time of the following code

k = 0;
for (i = 0; i < 1000 * n; i++) k++;

A

The loop runs 1000n times, which is O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the running time of the following code

k = 0;
for (i = 0; i < 2*n; i++) {
for (j = 0; j < 10000; j++) k++;
}

A

The outer loop runs 2n times, so its number of iterations is O(n). The inner loop runs 10,000 times, so it is O(1)

O(n) * O(1) = O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the running time of the following code

k = 0;
for (i = 1; i < (n*n); i *= 2) k++;

A

The loop runs log(n^2) times

log(n^2) = 2*log(n)

Therefore, O(log(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly