DualArrayDeque Flashcards

1
Q

What is the runtime of the DualArrayDeque get(i) operation?

A

O(1)

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

What is the runtime of the DualArrayDeque set(i,x) operation?

A

O(1)

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

What is the runtime of the DualArrayDeque add(i,x) operation?

A

O(min{i, n-i}), amortized

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

What is the runtime of the DualArrayDeque remove(i) operation?

A

O(min{i, n-i}), amortized.

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

How much extra space does a DualArrayDeque use to store n elements?

A

O(n)

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

What is the backing storage of a DualArrayDeque?

A

2 ArrayStacks.

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

What index i yields the worst-case runtime for the DualArrayDeque add(i,x) operation?

A

i=n/2

In this case, the runtime is O(n), since min{i, n-i}=n/2 when i=n/2.

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

What index i yields the best-case runtime for the DualArrayDeque add(i,x) operation?

A

Both i=0 and i=n-1.

These have O(1) runtime.

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

Pros of DualArrayDeque

A

Good (O(1) amortized) runtime to add and remove from both ends (so, a good implementation of the Deque interface)
Good (O(1)) random access.

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

Cons of DualArrayDeque

A

Not good to add/remove from the middle.
O(n) extra space required.
More complex than ArrayDeque, yet doesn’t give an improvement to runtime.

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