Arrays & Strings Flashcards

1
Q

Amortized insertion runtime

A

O(1)

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

Why is insertion runtime amortized?

A

Doubling the size of an array happens, but the next time it happens won’t be for a while. Which describes the insertion. It will have to perform O(n) operations to insert, but the next time it happens won’t be for a while.

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

Why is concatenation bad in languages that use it on strings?

A

Because a new string is created, then each character is copied over. i.e. First iteration copies x characters, second iteration copies 2x characters

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

What is the runtime of string concatenation?

A

O(n^2)

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

Are strings mutable in Java?

A

No, strings cannot be changed.

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

What is an array?

A

contiguous place in memory that holds items of equal size and is indexed by integers

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

Access of an array?

A

Constant O(1) : possible through index

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

What is runtime of writing to an array?

A

Constant O(1) : possible through index

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

How is an array constant access?

A

The value is found via this equation (memory_address + element_size x (index - first_index) done in the compiler

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

Memory of an array?

A

O(n) space

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

Delete at index of array? Not at end

A

O(n) to move all elements in array

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

Insert at index? Not at end

A

O(n) to shift all elements in array

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