Arrays Flashcards

1
Q

Show me how to initialize a regular array

A

int[] array = new int[5]
5 being the size

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

Show me how to initialize a array list

A

import java.util.ArrayList;

ArrayList<Integer> array = new ArrayList<>();</Integer>

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

Array Add to End Complexity

A

O(1)

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

Iterate through the Array complexity (search)

A

O(n)

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

Insert at begining and elsewhere in the array Complexity

A

O(n)

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

Delete and access elements at Index x

A

O(1)

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

How would you reverse an array?

A

Have a pointer at the start and end of the array, then loop through incrementing start then decrementing end making sure that they switch variables

While start < end
- temp value stores start
- start value = end value
- end value = temp value
- increment start
- decrement end, repeat

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

Difference between an array and an arraylist

A

Arrays have a set size
Arraylists are dynamic

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