T7 - Arrays and Subroutines Flashcards

1
Q

Arrays:

A

data structure that allows you to hold many items of data which is referenced by one identifier

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

To find an array length do

A

variable.len for python
variable.length in pseudocode

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

arrays and data types stored

A

All items of data in the array must be of the same data type

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

arrays works how

A

Information can be read from or added to the array using the index number

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

array indexes

A

Indexes in most languages start at 0 not 1

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

Arrays lengths

A

have fixed lengths

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

Linear search,

A
  • each item is examined in sequence until the item is found or the end of the list is reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Bubble sort:

A
  • Each item in a list is compared to the one next to it, and if it is greater, they swap places
  • At the end of one pass through the list, the largest item is at the end of the list
  • this is repeated until the items are sorted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to loop arrays

A

By using a FOR loop we can easily loop through an array.

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

Subroutines:

A

allow code that you intend to use a number of time to be grouped together under one name

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

eg of subroutines

A

Both functions and procedures are subroutines

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

features of subroutines

A

Values can be passed to both procedures and functions

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

functions and outputs

A

Functions will return a value after processing has taken place

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

procedures

A

Procedures - execute code in a subroutine, but they don’t return anything

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

arguements

A

Both functions and procedures have arguments = eg (“Hello”) or (1,6)

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

Parameters:

A

sum(a, b)
a and b are known as parameters

17
Q

Pros of subroutines:

A
  • They are useful to break up a large program into self-contained units
  • Each subroutine can be tested separately to make sure it works correctly
  • Many programmers can work on a large program at the same time, cutting down development time
  • can be re-used in other programs
  • can be stored in a subroutine library and used in different programs if required
  • Program maintenance is easier – if requirements change then just the affected subroutines need to be modified
18
Q

“scope” of a variable, constant, procedure or function

A

defines the parts of the program in which it is recognised and can be used

19
Q

Local variables:

A

only exist while the subroutine is executing
They are only accessible within the subroutine

20
Q

Global variables:

A

are accessible anywhere in the program

21
Q

global variable in pseudocode =

A

global score

22
Q

Global and local constants:

A

Constants follow the same rules as variables
A constant declared in the main program can be seen and used, but not changed, anywhere else

23
Q

Pros of local variables:

A

keep a subroutine self-contained,
it can be used in any program without variable names conflicting with those used in the calling program

24
Q

python length number of array

A

variable.len