Arrays Flashcards

1
Q

time complexity of accessing an index from an array

A

O(1)

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

how is array stored in memory?

A

statically allocated contiguous blocks

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

what’s soft removal

A

leave the removed data in the data structure unless it’s absolutely necessary to get rid of it.

e.g. in arraylists, the end of the array is controlled by size variable, so to remove the last item we can just decrement size by 1 without explicitly removing the data at that slot.

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

what’s hard removal

A

ensure the data you removed is completely removed from the backing structure.

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

what is arraylist

A

an abstraction built upon arrays that allows dynamic allocation of space without user knowledge.

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

what’s the size of an arraylist

A

number of data (non-null) being stored in it.

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

what’s the capacity of an arraylist

A

number of data that can be stored without a resize

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

what’s the amortized time complexity of adding to the back of an arraylist and why

A

O(1)*,
because normal case is O(1)
worst case is when a resizing is needed but it happens rarely

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

time complexity of adding elsewhere in the arraylist

A

O(n),
because we must shift data around to keep contiguity of data

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

time complexity of removing from the back of an arraylist

A

O(1)

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

time complexity of removing anywhere but the back of an arraylist

A

O(n) due to shifting

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