2.2.1 Programming Techniques Flashcards

1
Q

Sequence

A

Code is executed line-by-line, from top to bottom

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Branching (AKA Selection)

A

A certain block of code is run if a specific condition is met, using IF statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Iteration

A

A block of code is executed a certain number of times or while a condition is met. Uses FOR, WHILE or REPEAT UNTIL loops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Count-controlled VS Condition-controlled

A

Count-controlled: Iteration is repeated a given number of times
Condition-controlled: Iteration continues until a given condition is met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recursion

A

A programming construct in which a subroutine calls itself during its execution. This continues until the stopping condition is met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Advantages of recursion

A

Certain problems can be represented in fewer lines of code, making them less prone to errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Disadvantages of recursion

A
  • Inefficient use of memory.
  • Danger of stack overflow.
  • Difficult to trace. This difficulty grows with more function calls.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Recursion relies on a stack, in order for it to work. Explain how recursion uses the call stack.

A

Each time the function calls itself, a new stack frame is created within the call stack.
A finite number of stack frames are created until the base case is reached. The subroutine unwinds, and begins to pop information off the stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do stack frames contain?

A

Parameters, local variables and return addresses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe stack overflow during recursion

A

The call stack runs out of memory as a result of the subroutine calling itself too many times, causing the program to crash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does scope refer to?

A

The section of code in which the variable is available.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Local variables have limited scope. What does this mean?

A

They can only be accessed within the block of code in which they were defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Using local variables is considered good programming practice. Why?

A

It ensures subroutines are self contained, with no danger of variables being affected by code outside the subroutine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Global variables can be accessed across the whole program. What is this useful for?

A

Values that need to be used by multiple parts of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why are global variables not recommended?

A

They can be unintentionally overwritten and edited. They also require more memory than local variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A local variable exists within a subroutine with the same name as a global variable. Which variable takes precedence?

A

The local variable.

17
Q

Modular programming

A

A programming technique used to split large complex programs into smaller, self contained modules.

18
Q

Benefits of modularity

A

Makes problem easier to understand and approach
Makes it easier to divide tasks between a team and manage
Simplifies testing process as individual modules can be tested, improving reusability

19
Q

The top down approach is a popular technique for modularising programs. How does it work?

A

The problem is continually broken down into subproblems, until each can be represented as an individual blackbox which performs a certain task. This is known as stepwise refinement.

20
Q

Procedure/Function

A

Named blocks of code that perform a specific task.
Functions return a value, whereas procedures do not.

21
Q

Passing a parameter by value

A

A copy of the value is passed to the subroutine and discarded at the end.

22
Q

Passing a parameter by reference.

A

The address of the parameter is given to the subroutine, so the value of the parameter will be updated at the given address.

23
Q

Integrated Development Environment

A

A program which provides a set of tools to make it easier for programmers to write, develop and debug code.

24
Q

Stepping (IDE Feature)

A

Allows you to monitor the effect of each individual line of code by executing a single line at a time.

25
Q

Variable watch (IDE Feature)

A

Used to observe how the contents of a variable change in real-time through the execution of a program.

26
Q

Breakpoint (IDE Feature)

A

Allows users to set a point in the program at which the program will stop.

27
Q

Source code editor (IDE Feature)

A

Provides features such as autocompletion, indentation and syntax highlighting to make the coding process easier.