2.2.1 Programming Techniques Flashcards
What are the three main programing constructs?
- Sequence
- Selection / Branching
- Iteration
What is sequence?
Programing construct
Instructions that are executed one after the other, in order.
What is selection / branching?
Programming construct
When the computer may execute different instructions based on a condition.
What is iteration?
Programming construct
When an instruction or group of instructions is run multiple times.
What is recursion?
A function defined in terms of itself, with a base case that terminates the recursion.
What are the advantages of recursion over iteration?
- More natural for some problems
- Uses less lines of code
- Divide and conquer recursive algorithms are often faster
What are the advantages of iteration over recursion?
- Requires less memory
- Won’t cause stack overflow errors
- Iteration is normally faster than recursion
- Easier to trace
What are the similarities between recursion and iteration?
They can both be used to solve the same problems.
They can both involve running the same section of code multiple times.
What are the differences between recursion and iteration?
A recursive solution creates new local variables each time it is called.
An iterative solution uses the same local variables each time the loop runs.
What is modular program design?
When a program is divided into seperate self contained subroutines/modules which can be written and tested individually.
Subroutines/modules may be divided further into smaller subroutines/modules.
What is a subroutine/module?
A named section of a program that performs a specific task.
What is a function?
A named section of a program that performs a specific task and returns a value.
What is a procedure?
A named section of a program that performs a specific task but does not return a value.
What are the types of subroutine/module?
Functions and procedures.
What is a parameter?
An item of data that is passed into a subroutine/module when it is called, and used as a variable within the subroutine/module when it is used.
What are the advantages of designing a program modularly?
- Code can be reused in the same and other programs, which saves time
- Each module can be tested independently, which makes finding bugs easier
- Different modules can be worked on by different programers, which saves time and allows people to work on problems they are specialised for
- Programmers only have to know the inputs and outputs of the module they are working on, and don’t have to understand the whole problem
- It can make the solution more memory efficient (because of local variables)
- It can make the code less difficult to write (because it is split into chunks)
What is a variable?
A named memory location used to store data that can change while the program is running.
What is a constant?
A named memory location used to store data that cannot change while the program is running.
What is scope?
For variables
The range of statements/subroutines that a variable can be used in.
What is a global variable?
A variable that is accessible throughout the whole program