Arrays Flashcards

1
Q

Why are arrays better at storing data than variables?

A

If you have lots of similar data you can store it in 1 array instead of multiple variables as each variable is inefficient.

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

What is an array?

A

A data structure that can store a collection of data values under one name.

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

What is each piece of data in an array called?

A

an element

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

How can each element be assessed in an array?

A

using its position or index

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

When are arrays most helpful?

A

When you have lots of related data that you want to store and it doesn’t make sense to use separate values.
e.g. the names of pupils in a class, marks in a test etc

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

How are they similar to variables?

A

Some languages require you to declare arrays before you use them.

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

What is a one-dimensional array like?

A

lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
How does this array work?
array rowers[4]
rowers[0] = "Mark"
rowers[1]  = "Adam"
rowers[2] = "Shelly"
rowers[3] = "Tobias"
A

The first line creates the array “rowers” and makes it size 4 (contains only 4 elements). The other lines assign the strings (names) in their positions in the array: 0,1,2 and 3.

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

How can you retrieve elements from an array?

A

Use the name of the array and element’s position. Positions are numbered always starting at 0.

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

How to change the value of the elements?

A

Reassigning the array position to a different data value. The previous value will be removed completely.

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

How can FOR loops improve arrays if you combine them?

A

More systematic way of accessing and changing all of the elements in an array. They can also be used to search for specific elements or make a similar change to lots of elements.

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

What is a two-dimensional array?

A

A one-dimensional array where each element is also a one-dimensional array.

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

How is the position of an element written in a two-dimensional array?

A

[a,b] or [a][b], where a represents the position of the one-dimensional list that the element is in and b represents its position within that one dimensional list.

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

An example of a two-dimensional array:

A

trees = [[“oak”, “ash”], [“beech”, “cedar”], [“pine”, “elm”]]

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

How do you change elements in a two-dimensional array?

A

The exact same as in a one-dimensional array.

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

How can two-dimensional arrays be used to store information about a digital image?

A
  • each pixel’s information stored as an element in an array
  • programmers can manipulate the image using array commands
  • e.g. changing the value of pixels, cutting rows and columns out of the image etc.