2.2.1 programming techniques Flashcards
name 3 programming constructs
sequence, branching and iteration
which 2 categories of loop is iteration split up into?
count controlled and condition controlled
describe how the branching programming construct works
a certain block of code is run is a specific condition is met, using if statements
what is recursion?
a programming construct in which a subroutine call itself during execution until the stopping condition is met
what is the base case in recursion?
a condition that must be met in order for the recursion to end
state 2 advantages of recursion
can be represented in fewer lines of code, easier to express some function recursively that using iteration
state a disadvantages of recursion
inefficient use of memory, danger of stack overflow, difficult to trace
give 2 piece of information that are stored on the call stack
parameters, return addresses and local variables
define scope
the section of the program in which a variable is accessible
give 2 advantages of suing local variables over global variables
less memory is used, self contained so unaffected bye code outside the subroutine, take precedence over global variables with the same name
what is top down designed?
a technique used to modularise programs in which the problem is continually broken down into sub problems, until each can be represented as an individual, self contained module which performs a certain task
state 2 advantages of a modular design
makes a problem easier to understand and approach, simpler to divide task between a team, easier to project manage
give another name for top down design
stepwise refinement
what is the difference between procedures and functions?
function must always return a single value while a procedure does not always have to return a value
what does it mean to pass a parameter to a subroutine by reference
the address in memory of the parameter Is passed to the subroutine so its value outside the subroutine will be updated