2.1.2 - Thinking Ahead Flashcards

Component 2

1
Q

What are preconditions?

A

Conditions that must be met before an algorithm can be run successfully.

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

What are the benefits of specifying preconditions in an algorithm’s documentation?

A
  • Ensures the user knows what checks must be carried out before calling the subroutine
  • If there are no preconditions, then the user can be confident that necessary checks will be carried out in the subroutine itself, thus saving unnecessary coding.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What would the preconditions be for a binary search tree?

A

The tree must be ordered

Each parent node can have a maximum of 2 child nodes

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

What could be the preconditions for an algorithm that renders a CD cube based on dimensions provided by the user?

A

The size of the cube cannot be negative and must be a number

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

What are reusable components?

A

Components that are written in a way that makes it possible to use the code again in another project. An example is code libraries that can be used when developing a program.

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

What are the benefits of writing reusable components?

A
  • The components can be used in a future program, and they do not need to be rewritten which saves time
  • Can be tested independently (self-contained) which may make finding errors simpler – Reduces testing requirements
  • Can update one module and it will change all programs that use it – don’t have to change every place the code is used, which avoids accidentally missing one.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the benefits of using reusable components?

A

They are already written and tested so saves time writing them out again

Can be cached to speed up processing

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

What is caching?

A

The temporary storage of instructions or data that has been recently used, in fast memory on the processor chip (cache) so that if they are needed again, they can be retrieved very quickly.

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

What are the benefits of caching?

A
  • Cached data items are faster to retrieve than in a secondary storage device
  • Speeds up the execution of whole programs (reduced latency)
  • Means that the RAM doesn’t need to be accessed as frequently saving time and bus bandwidth.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the drawbacks of caching?

A
  • Cache Hit Rates – If the cache is checked first, and the data is not there, this will add some time to the execution.
  • Only beneficial if the instruction/data is repeatedly used
  • Cache is relatively expensive
  • Cache size is limited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is cache?

A

Small high-speed memory located on the CPU / GPU

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