Jan Mocks Flashcards

1
Q

Recursion

A

When a subroutine calls itself within its own subroutine

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

A recursive subroutine should:

A

Contain a stopping condition (base case)
For any input value other than the stopping condition, the subroutine should call itself
The stopping condition should be reachable within a finite number of times
- without these characteristics a recursive subroutine may call itself indefinitely resulting in a stack overflow

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

Is recursion good

A

Recursion is not very memory efficient. Every time a recursive function calls itself the processor needs to remember where it was before it jumps to the new copy so it knows where to return later.
The processor also needs to remember the values of all the previous variables, as they are local to those copies of the recursive function- using stacks which takes up space in memory

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

Stack overflow

A

Recursive subroutines calls itself too many times before reaching its terminating condition you could run out of memory and cause the program to crash

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

When should you use recursion over iteration

A

Tree traversal algorithm
Performing a flood fill in a graphics application

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

Local variable accessibility

A

Single subroutine only

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

Local variable created

A

Declared inside a subroutine

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

Local variable destroyed

A

When the subroutine exits

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

Global variable accessibility

A

Entire program

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

Global variable created

A

Declared outside of a subroutine. Typically at the start of a program

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

Global variable destroyed

A

When the program ends

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

Local variable

A

Created when the subroutine is called

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

Global variable

A

Created when the program starts

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

Good program practice (g+l variables)

A

A system of passing in required values to the subroutine via parameters and returning values is considered safer and better programming practice

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

Why is overuse of global variables bad

A

Excessive, unnecessary use of global variables can make programs hard to test, debug and maintain

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

When should you use local variables

A

Should be used whenever possible

17
Q

Modularity

A

The concept on breaking a large program or problem down into smaller chunks

18
Q

Modularity goal

A

To design a program in a way that each module carries out single, specific task

19
Q

What are modules also known as

A

Subroutine
Procedures
Functions
Methods

20
Q

Procedure

A

Is a block of code that takes in zero, one or more parameters and performs a set task

21
Q

Function

A

Block of code that takes in zero, one or more parameters, performs a set task, and returns a value

22
Q

Return value

A

The return value from a function does not need to be assigned to a variable as long as it returns something valid

23
Q

What does the interface outline

A

The name of the subroutine
The list of parameters it requires when it is called
The data type for those parameters
The order of those parameters
- if the subroutine interface is for a function, it also typically includes the data type of its return value

24
Q

What does the first line of a subroutine specify

A

The interface for that subroutine

25
Q

Two methods when passing data into a subroutine

A

Passing by value
Passing by reference