01 - Arrays Flashcards

1
Q

What is an Algorithm?

A

A step-by-step procedure for solving a problem

May be performed by a human or a machine

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

What is a data structure?

A

A way of organising information

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

What is an array? (According to John Lewis)

A

A sequence of indexed elements

It has a fixed length

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

What is the time complexity for accessing an index in an array?

A

Accessed in O(1)

Array elements are accessed by their indices which are unique and fixed

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

What field stores the size of an array in Java?

A

length

e.g. arrayPotter.length

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

How are array elements accessed in Java?

A

Using integers enclosed in square brackets

e.g. array[i]

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

Can the lower bound of an array be chosen in java?

A

No

The lower bound is always 0

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

Are arrays passed by reference or by value?

A

By reference

Arrays are objects which means that they are manipulated by reference

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

Can one array hold primitive values of different types?

A

No

Arrays of primitive types (int, char), can only hold one type

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

Can an array hold objects from different classes?

A
Only partly
If an array is defined to hold objects of class C, it can also hold any objects which are subclasses of C
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of these are invalid?

a: int[] myArray;
b: int[] myArray = int[10];
c: int[] myArray = new int[10];
d: int[] myArray = {1,1,2,3,5,8}

A

b: int[] myArray = int[10]

Array initialisation much be prefixed with the ‘new’ keyword

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

How do you test equality between arrays?

A

Arrays.equals(array1,array2)

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

When are two arrays considered equal?

A

When they contain exactly the same elements in the same order

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

Does Arrays.equals() work on 2D arrays?

A

No

Arrays.deepEquals() must be used instead

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