2.1.2 - Thinking Ahead Flashcards
Component 2
What are preconditions?
Conditions that must be met before an algorithm can be run successfully.
What are the benefits of specifying preconditions in an algorithm’s documentation?
- 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.
What would the preconditions be for a binary search tree?
The tree must be ordered
Each parent node can have a maximum of 2 child nodes
What could be the preconditions for an algorithm that renders a CD cube based on dimensions provided by the user?
The size of the cube cannot be negative and must be a number
What are reusable components?
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.
What are the benefits of writing reusable components?
- 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.
What are the benefits of using reusable components?
They are already written and tested so saves time writing them out again
Can be cached to speed up processing
What is caching?
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.
What are the benefits of caching?
- 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.
What are the drawbacks of caching?
- 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
What is cache?
Small high-speed memory located on the CPU / GPU