2.1.2 Thinking Ahead
No description yet. This curated deck is ready for daily study.
Card preview (12)
What are preconditions?
• Conditions that must be met before an algorithm can be run successfully. • Something that can be evaluated to give either a True or False outcome.
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?
The data must be ordered
What could be the preconditions for an algorithm that renders a 3D 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?
• One piece of code can be used many times making code more efficient. • No need to write the same code multiple times, saving development time. • Easier error detection as fix once and it corrects in each place. Less likely to have errors as code is not written multiple times. • Makes it easier to maintain the program. • Can be taken and used in different programs as well as the program they are written in. Can be used in a program library. • Reduced testing requirements. They have already been tested as used before. • Can be cached to speed up processing.
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 • More efficient code which will use less memory • May require less technical knowledge as code can be just re-used rather than written.
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
What items could be cached if someone was programming the game of tic-tac-toe (noughts and crosses)?
• Player pieces • The board • PlayerNames • Code for swapping players • Code for checking if valid move