RootishArrayStack Flashcards

1
Q

What is the runtime of get(i) for a RootishArrayStack?

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 set(i,x) for a RootishArrayStack?

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 add(i,x) for a RootishArrayStack?

A

O(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 remove(i) for a RootishArrayStack?

A

O(n-i) amortized

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

What is the extra space required for a RootishArrayStack to store n elements?

A

O(sqrt(n))

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

What is the backing storage in a RootishArrayStack?

A

O(sqrt(n)) arrays of sizes 1, 2, 3, 4, ….

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

The first r blocks of a RootishArrayStack can store up to how many elements?

A

r(r+1)/2.

The first r blocks have capacity 1, 2, 3, 4, …, r and 1+2+3+…+r = r(r+1)/2

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

What index i yields the worst-case running time for the add(i,x) operation in a RootishArrayStack?

A

index i=0.

Adding to the first position requires all remaining n elements to be shifted to the right, which is O(n) work.

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

What index i yields the best-case running time for the add(i,x) operation in a RootishArrayStack?

A

index i=n-1.

I.e. adding to the end is fast since it doesn’t require much shifting. You may need to add a new block, but allocating a new block does not take much time in most systems.

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

Pros of RootishArrayStacks.

A
Use only O(sqrt(n)) extra space to store n elements.
Fast get(i) and set(i,x) (i.e. good random access)
Its runtimes are not even amortized, unless array allocation is not constant time (and if it isn't constant, it's still good amortized time.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Cons of RootishArrayStacks

A

Slightly more complex implementation than some other array-based implementations of the list interface.
Adding and removing from the front is O(n), so this is not a good choice to implement the Deque interface.

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