Part 2, Patterns, algorithms and programs 2 Flashcards

1
Q

This can be used to produce a sequence of numbers and store the sequence inside a list

A

when might you apply the list generation pattern

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

in python how would you append an item to an end of a list

A

to perform this follow the following syntax

List = []

List = list + [1]

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

1  initialise the input with a non-empty list

2  set best to the first item in the list

3  for each item in the list:

 3a   if the item is better than best:

  3ai    set best to the item

  1.  print best
A

what are the 6 steps of the find the best value pattern

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

what are the seven steps involved with the list transformation pattern

A

 initialise the input_list with the given values

2  initialise other inputs of the problem

3  initialise the output_list to the empty list

4  for each input_value of the input_list:

 4a   transform the input_value into an output_value

 4b   append the output_value to the output_list

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

1  initialise the input list

2  set found to the null value

3  for each item in the list:

 3a   if the item satisfies the condition:

  3ai    set found to the item

4  print found

A

what are the 6 steps of the find value pattern

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

what do these two considerations refer to

  1. the min and max size of the list itself
  2. the min/max and boundary values of the elements inside the list
A

when testing lists what are two considerations that must be taken into consideration when writing tests

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

what are these a sub category of

  1. counting problems
  2. aggregation problems
  3. retrieval (or search) problems
A

name 3 types of reduction problems

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

what are the 6 steps of the find value pattern

A

1  initialise the input list

2  set found to the null value

3  for each item in the list:

 3a   if the item satisfies the condition:

  3ai    set found to the item

4  print found

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

how is the value NULL expressed in python

A

this is expressed as None in python

(note the capital N)

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

when would you apply the find the best value pattern to an algorithm

A

This pattern can be used to find the best value in the list such as the hottest or coldest day

(note it has 1 redundant check being the first item in the list and returns the first best item found)

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

what are the 7 steps involved with the list filtering pattern

A

1  initialise the input_list with the given values

2  initialise other inputs of the problem

3  initialise the output_list to the empty list

4  for each input_value of the input_list:

 4a   if the input_value satisfies the condition:

  4ai    append the input_value to the output_list

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

This pattern can be applied in problems that involve counting how many items are in a list or counting how many of the items in the list satisfy a given condition

A

explain when the counting problem can be applied to an algorithm

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

to perform this follow the following syntax

List = []

List = list + [1]

A

in python how would you append an item to an end of a list

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

when would we apply the list transformation pattern

A

This pattern can be used in cases where we wish to transform every element in a list into a new value

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

in python how can you iterate over all values in a list while at the same time using the currently held value from the list from the iteration

A

when might you use this

For element in list:

If element > 30:

Do something

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

what are the 6 steps of the aggregate pattern

A

1 initialise the input list

2  initialise the aggregator with a suitable value

3  for each number in the list:

 3a   if the number satisfies the condition:

  3ai    update the aggregator according to the value of the number

4  print the aggregator

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

what does the following python function do

sum()

A

which python function does this describe

returns a number, the sum of all items in an iterable.

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

when would you apply the aggregate pattern

A

This pattern may be applied when we need to aggregate (something formed by adding together several amounts or things) all numbers in a list or when we want to only aggregate the numbers in a list that satisfy a certain condition

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

name 3 types of reduction problems

A

what are these a sub category of

  1. counting problems
  2. aggregation problems
  3. retrieval (or search) problems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

explain when the counting problem can be applied to an algorithm

A

This pattern can be applied in problems that involve counting how many items are in a list or counting how many of the items in the list satisfy a given condition

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

this term involves taking a list and producing a single value from the values in the original list

A

what does the term reduce/reduction mean in terms of lists

22
Q

which python function does this describe

returns a number, the sum of all items in an iterable.

A

what does the following python function do

sum()

23
Q

This pattern may be applied when we need to aggregate (something formed by adding together several amounts or things) all numbers in a list or when we want to only aggregate the numbers in a list that satisfy a certain condition

A

when would you apply the aggregate pattern

24
Q

Iterable: Required. The sequence to sum

Start: Optional. A value that is added to the return value

A

the syntax for the python sum() function is as follows but what are each of the parameters for

sum(iterable, start)

25
Q

when might you use this

len(object)

A

using python youd like to find the length of an object (list, string, etc) which built in function would you use

26
Q

1 initialise the input with a non-empty list

2  set best_position to 0

3  for each position from 1 to length of list – 1:

 3a   if the item at position is better than the item at best_position:

  3ai    set best_position to position

  1.  print best_position
A

what are the 6 steps of the find position of first best value pattern

27
Q

when would you apply the find value pattern to an algorithm

A

This pattern can be applied when we wish to extract or search for a single value from a list (note the item returned will be the last item found that satisfied the condition)

28
Q

 initialise the input_list with the given values

2  initialise other inputs of the problem

3  initialise the output_list to the empty list

4  for each input_value of the input_list:

 4a   transform the input_value into an output_value

 4b   append the output_value to the output_list

  1.  print the output_list
A

what are the seven steps involved with the list transformation pattern

29
Q

1 initialise the input list

2  initialise the aggregator with a suitable value

3  for each number in the list:

 3a   if the number satisfies the condition:

  3ai    update the aggregator according to the value of the number

4  print the aggregator

A

what are the 6 steps of the aggregate pattern

30
Q

the syntax for the python sum() function is as follows but what are each of the parameters for

sum(iterable, start)

A

Iterable: Required. The sequence to sum

Start: Optional. A value that is added to the return value

31
Q

This pattern can be used to find the best value in the list such as the hottest or coldest day

(note it has 1 redundant check being the first item in the list and returns the first best item found)

A

when would you apply the find the best value pattern to an algorithm

32
Q

what are the 6 steps of the find position of first best value pattern

A

1 initialise the input with a non-empty list

2  set best_position to 0

3  for each position from 1 to length of list – 1:

 3a   if the item at position is better than the item at best_position:

  3ai    set best_position to position

  1.  print best_position
33
Q

this is expressed as None in python

(note the capital N)

A

how is the value NULL expressed in python

34
Q

1  initialise the inputs

2  set value to the first value of the sequence

3  set sequence to the empty list

4  append value to the sequence

5  while the termination condition is not true:

 5a   set value to the next value of the sequence

 5b   append value to the sequence

  1.  print the sequence
A

what are the 8 steps involved with the list generation pattern

35
Q

1  initialise the input_list with the given values

2  initialise other inputs of the problem

3  initialise the output_list to the empty list

4  for each input_value of the input_list:

 4a   if the input_value satisfies the condition:

  4ai    append the input_value to the output_list

  1.  print the output_list
A

what are the 7 steps involved with the list filtering pattern

36
Q

what are the 6 steps of the counting problem

A

1  initialise the input list

2  set a counter to zero

3  for each item in list:

 3a   if the item satisfies the condition:

  3ai    increment the counter, i.e. add 1 to it

4  print the counter

37
Q

using python youd like to find the length of an object (list, string, etc) which built in function would you use

A

when might you use this

len(object)

38
Q

This pattern can be used in cases where we wish to transform every element in a list into a new value

A

when would we apply the list transformation pattern

39
Q

when might you apply the list generation pattern

A

This can be used to produce a sequence of numbers and store the sequence inside a list

40
Q

This pattern can be applied when we wish to extract or search for a single value from a list (note the item returned will be the last item found that satisfied the condition)

A

when would you apply the find value pattern to an algorithm

41
Q

when might you apply the list filtering pattern

A

This can be used to filter out particular values from a given list

42
Q

when testing lists what are two considerations that must be taken into consideration when writing tests

A

what do these two considerations refer to

  1. the min and max size of the list itself
  2. the min/max and boundary values of the elements inside the list
43
Q

1  initialise the input list

2  set a counter to zero

3  for each item in list:

 3a   if the item satisfies the condition:

  3ai    increment the counter, i.e. add 1 to it

4  print the counter

A

what are the 6 steps of the counting problem

44
Q

This is similar to Pattern 2.8 find the best value however it has no redundant checks and instead returns the position/index of the best value

A

when would you apply the find position of first best value pattern to an algorithm

45
Q

This can be used to filter out particular values from a given list

A

when might you apply the list filtering pattern

46
Q

when might you use this

For element in list:

If element > 30:

Do something

A

in python how can you iterate over all values in a list while at the same time using the currently held value from the list from the iteration

47
Q

what are the 6 steps of the find the best value pattern

A

1  initialise the input with a non-empty list

2  set best to the first item in the list

3  for each item in the list:

 3a   if the item is better than best:

  3ai    set best to the item

  1.  print best
48
Q

when would you apply the find position of first best value pattern to an algorithm

A

This is similar to Pattern 2.8 find the best value however it has no redundant checks and instead returns the position/index of the best value

49
Q

what does the term reduce/reduction mean in terms of lists

A

this term involves taking a list and producing a single value from the values in the original list

50
Q

what are the 8 steps involved with the list generation pattern

A

1  initialise the inputs

2  set value to the first value of the sequence

3  set sequence to the empty list

4  append value to the sequence

5  while the termination condition is not true:

 5a   set value to the next value of the sequence

 5b   append value to the sequence

  1.  print the sequence