2.2.1 Programming techniques Flashcards
2.2.1 A)
What’s a programming construct used for.
used to represent control flow structured programming
2.2.1 A)
What are the 3 programming constructs.
Sequence , branching/selection , iteration
2.2.1 A)
What is a sequence in term of programming constructs.
Code is executed line by line top to bottom
2.2.1 A)
What is branching / selection in term of programming constructs.
Code is run if a specific condition is met (if statement)
2.2.1 A)
What is iteration in term of programming constructs.
Code is executed certain number of times or while a condition is met. (for/while statement)
2.2.1 B) What is recursion
A construct in which a subroutine calls apron itself during execution. This continues until a certain condition is met ( stopping condition ).
2.2.1 B)
What is recursion like and how is it different.
produces the same result as iteration but suited to certain problems.
2.2.1 B)
What’s the advantage of recursion.
CAN be represented in fewer lines which can lead to less errors. But it needs to be clearly defined to reach a stopping condition
2.2.1 B)
How do stacks work in recursion.
Every time the stack calls itself a new stack frame is created within the stack. Stack frames are created until stopping condition is met and subroutine unwinds. Information from the call stack being popped off the stack.
2.2.1 B)
What is recursion used for?
For storing parameters, local variables and return addresses are stored allowing the subroutine to return to a particular point during execution.
2.2.1 B)
What’s the disadvantage of recursion
inefficient use of memory, danger of stack overflow (if it calls it self too many times call stack runs out of memory) this can lead to the program crashing, Difficult to trace.
2.2.1 B)
How can recursion be improved ?
can use tail recursion its a form of recursion which implemented in a more eff way, less stack space is needed
2.2.1 C)
What is scope
refers to the section of code the variable is available too.
2.2.1 C)
What is a local variable
It has a limited scope, only can be accessed within a block of code in which they were defined.
2.2.1 C)
Adv of local variable
multiple local variables can have same name not effect each other. good practice ensures subroutines are self contained.