(GCSE ARCHIVE) Algorithms, Design, and Testing Flashcards
What is structured programming?
Structured programming involves decomposing a program into smaller manageable modules. Each of these modules is then decomposed even further repeatedly until eventually reaching modules that perform specific tasks.
What are the advantages of structured programming?
- Coding is easier because you’re only writing subroutines that carry out very simple tasks
- Lots of programmers can work on one program as each module can be written independently.
- It’s easier to test structured programs as each module can be tested individually.
- You will be able to reuse the subroutines and modules in programs you write in the future.
- Individual subroutines and modules can be fixed and updated without affecting the rest of the program.
What is authentication?
The process of verifying the identity of a user before they’re allowed to access anything, such as through passwords.
Ways of increasing the security of a password-based authentication system
- Limit the number of failed authentication attempts a user can have before locking their account for safety.
- Force users to use strong passwords that cannot be easily guessed.
- Force users to regularly change their passwords.
What is input validation?
Checking if data meets certain criteria before passing it into the program. An example would be checked that a phone number only has numbers in it.
What are the 5 types of common input validation checks?
- Range checks
- Presence checks
- Format checks
- Length checks
- Look-up table
Range check
Checks the data is within a specific range of values.
Presence check
Checks that data has actually been entered.
Format check
Checks the data has the correct format (e.g. a date).
Look-up check
Checks data against a table of acceptable values.
Length check
Checks the data is the correct length (e.g. a password must be between 8-20 characters).
Ways to improve the maintainability of code
- Only use global variables when necessary, as they could affect the rest of your code (e.g. somebody else uses the same variable name as you).
- Use local variables in subroutines instead, as they don’t affect anything outside of the subroutines they’re in.
- Variables, subroutines, and parameters should be named appropriately, and refer clearly to what they are. This avoids confusion later on and makes it easier to keep track of what each variable does.
- Comments (written after # or //) are useful for explaining the key feature of a program. Clear and well written comments are important to help other programmers understand your program.
What are the 2 types of errors in programming?
- Syntax Error: When the compiler/interpreter doesn’t understand something you’ve typed, because it doesn’t follow the rules or grammar of the programming language.
- Logic errors: When the compiler/interpreter is able to run the program, but the program does something unexpected.
Why is it harder to find the source of a logic error?
- Syntax errors can be diagnosed by a computer, and they often return the line of code in which a syntax error is found.
- Logic errors aren’t picked up by compilers/interpreters, as the code still follows the syntax. Logic errors are found through systematically testing a program using a test plan.
What are the three types of test data?
- Normal data: Typical, sensible data that the program should accept.
- Boundary (extreme) data: Valid or invalid data that is on either side of the boundary of what the program should accept as normal. data.
- Erroneous data: Invalid data that the program should not accept.
What are trace tables useful for?
- Trace tables are a simple way of testing that a piece of code is working correctly.
- They keep track of the values of certain variables take as you go through the code.
- Their main use is to ‘dry run’ a subroutine or algorithm to make sure there are no logic errors.
- They can help you to understand what a piece of code is doing.
What is time efficiency?
- Many algorithms are made to do the same thing, and each algorithm takes a certain amount of ‘time’ to complete a task.
- Algorithms that take less ‘time’ to complete the task have better time efficiency.
- When programmers talk about the ‘time’ an algorithm takes, they don’t mean real-life time. They measure things like the number of times memory was accessed, the number of CPU cycles taken to execute commands, or the number of times a loop was created.
What are the three key techniques for computational thinking?
- Decomposition
- Abstraction
- Algorithmic Thinking
What is decomposition? Give one advantage of using this technique.
- The process of breaking down a complex problem down into smaller sub-problems and solving each one individually.
- You can assign different sub-problems to people in a team to solve a large problem faster.
What is abstraction?
The process of picking out the important bits of information from a problem, and ignoring all the specific details that don’t matter.
What is algorithmic thinking?
Algorithmic thinking is a logical way of getting from a problem to a solution. If the steps you take to solve a problem follow an algorithm, then they can be reused and adapted to solve similar problems in the future.
What is a benefit of using pseudocode to write algorithms?
- It clearly shows an algorithm’s steps, and it can be written quickly, without worrying about the syntax of any particular programming language.
- You can write it differently, as long as the person reading it can follow it and understand what you mean.
- You can easily convert it to any programming language.
Pseudocode Algorithm: Outputting a person’s salary after a 10% bonus is added to it.
salary <– USERINPUT
newsalary <– salary * 1.1
OUTPUT newsalary
Pseudocode Algorithm: When registering on a website, a user’s password should be:
- More than 6 characters long
- Different from their username
Write an algorithm to check the validity of their password, and state why their password is invalid.
username <– USERINPUT
password <– USERINPUT
IF length of password <= 6 THEN
OUTPUT 'Password is too short'
ELSE IF password == username THEN
OUPUT 'Password is the same as username.'
ELSE
OUTPUT 'Password is valid.'