ArrayList Flashcards

1
Q

What is a Array?

A

Arrays hold values of the same type at contiguous memory locations.

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

What are we concerned about in a Array?

A

The position/index of an element and the element itself.

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

Advantages

A

-Store multiple elements of the same type with one single variable name
-Accessing elements is fast as long as you have the index, as opposed to linked lists where you have to traverse from the head.

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

Disadvanteges

A

-Addition and removal of elements into/from the middle of an array is slow because the remaining elements need to be shifted to accommodate the new/missing element. An exception to this is if the position to be inserted/removed is at the end of the array.
-For certain languages where the array size is fixed, it cannot alter its size after initialization. If an insertion causes the total number of elements to exceed the size, a new array has to be allocated and the existing elements have to be copied over. The act of creating a new array and transferring elements over takes O(n) time.

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

Subarray

A

A range of contiguous values within an array.
Example: given an array [2, 3, 6, 1, 5, 4], [3, 6, 1] is a subarray while [3, 1, 5] is not a subarray.

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

Subsequence

A

A sequence that can be derived from the given sequence by deleting some or no elements without changing the order of the remaining elements.
Example: given an array [2, 3, 6, 1, 5, 4], [3, 1, 5] is a subsequence but [3, 5, 1] is not a subsequence

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

Insertion

A

Insert O(n) Insertion would require shifting all the subsequent elements to the right by one and that takes O(n)

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

Access , Search , Search (sorted array)

A

Access O(1)
Search O(n)
Search (sorted array) O(log(n))

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

Insert (at the end)

A

O(1) Special case of insertion where no other element needs to be shifted

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

Remove

A

O(n) Removal would require shifting all the subsequent elements to the left by one and that takes O(n)

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

Remove (at the end)

A

O(1) Special case of removal where no other element needs to be shifted

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

Why do we need arrays?

A

Arrays are best for storing multiple values in a single variable
Arrays are better at processing many values easily and quickly
Sorting and searching the values is easier in arrays

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