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
when might you use this ## Footnote **len(object)**
using python youd like to **find the length of an object** (list, string, etc) which built in function would you use
26
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
what are the 6 steps of the **find position of first best value pattern**
27
when would you apply the **find value pattern** to an algorithm
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
 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
what are the seven steps involved with the **list transformation pattern**
29
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
what are the 6 steps of the **aggregate pattern**
30
the syntax for the python sum() function is as follows but what are each of the parameters for sum(iterable, start)
Iterable: Required. The sequence to sum Start: Optional. A value that is added to the return value
31
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)
when would you apply the **find the best value pattern** to an algorithm
32
what are the 6 steps of the **find position of first best value pattern**
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
this is expressed as **None** in python | (note the capital N)
how is the value **NULL** expressed in python
34
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
what are the 8 steps involved with the **list generation pattern**
35
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
what are the 7 steps involved with the **list filtering pattern**
36
what are the 6 steps of the **counting problem**
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
using python youd like to **find the length of an object** (list, string, etc) which built in function would you use
when might you use this ## Footnote **len(object)**
38
This pattern can be used in cases where we wish to transform every element in a list into a new value
when would we apply the **list transformation pattern**
39
when might you apply the **list generation pattern**
This can be used to produce a sequence of numbers and store the sequence inside a list
40
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)
when would you apply the **find value pattern** to an algorithm
41
when might you apply the **list filtering pattern**
This can be used to filter out particular values from a given list
42
when **testing lists** what are two considerations that must be taken into consideration when writing tests
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
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
what are the 6 steps of the **counting problem**
44
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
when would you apply the **find position of first best value pattern** to an algorithm
45
This can be used to filter out particular values from a given list
when might you apply the **list filtering pattern**
46
when might you use this ## Footnote For *element* in *list:* If *element \>* 30: Do something
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
what are the 6 steps of the **find the best value pattern**
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
when would you apply the **find position of first best value pattern** to an algorithm
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
what does the term **reduce/****reduction** mean in terms of lists
this term involves taking a list and producing a single value from the values in the original list
50
what are the 8 steps involved with the **list generation pattern**
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