Programming Techniques Flashcards

1
Q

Stepwise Refinement

A

Breaks problem into progressively smaller sections until each section can be written in single procedure/function.

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

Top-down design

A

Produced through the process of stepwise refinement.

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

Function

A

Block of code which performs a single task. Returns a single value. Uses local variables.

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

Procedure

A

Block of code which performs a task. Receives parameter values. Uses local variables. It may or may not produce a single value

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

Benefits of using proc/func Features of struct progs

A

Can be tested separately. Easier to maintain the program. Main program is simpler and code clearly structured. Use of library routines saves time. Code is reusable. Produced faster and to higher standard as proc/func may be shared between coders.

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

Variable

A

An identifier / memory location representing a value needed by the program. Value may change while the program is running.

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

Parameter

A

Is an item of data supplied to a procedure or function. Data can be passed by reference or by value. Used as local variables.

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

Pass by value

A

Only actual value passed. Procedure/function can only modify a copy of original variable (and not the original variable itself).

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

Pass by reference

A

Provides procedure/function with actual address to original variable therefore allowing it to permanently alter its contents.

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

Local Variables

A

A variable defined within one part of the program (procedure/function) & is only accessible in that part. Data contained is lost when execution of that part of program is completed. The same variable names can be used in different procedures and functions. An example of a local variable could be a loop counter.

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

Global Variables

A

A variable defined at the start of the program which exists throughout the program (including within functions and procedures). Global variables allow data to be shared by modules. They are overridden by local variables with the same name
An example of a global variable could be VAT rate.

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

Use of stack

A

To help control the flow of instructions. When a subroutine is called the return address is placed on the stack followed by the parameters of the subroutine (if there are any). When the subroutine executes it first pops the parameters off the stack. When it finishes it pops the return address off the stack so control can pass back to the instruction at the calling address.

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

Backus-Naur Form

A

(BNF) is a notation technique used to unambiguously describe the syntax of programming languages.

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

Why is BNF needed

A

To unambiguously define the syntax of a computer language.

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

Recursion in BNF

A

::= 0|1|2|3|4|5|6|7|8|9

::= |

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

Syntax Diagrams – Purpose

A

To define terms unambiguously (for a computer language).

17
Q

Infix Notation

A

The way we normally work e.g. 5 + 6

18
Q

Reverse Polish Notation

A

Also known as postfix notation e.g. 5 6 +

19
Q

RPN →infix conversion

A
  1. Completely parenthesize the infix expression according to order of priority you want. 2. Move each operator to its corresponding right parenthesis. 3. Remove all parentheses.
20
Q

RPN Advantages

A

Simpler to evaluate by a machine (no need for brackets). Can be evaluated as they are entered, they are not limited to a certain number of operators in an expression.

21
Q

RPN↔infix - stacks

A

Stacks are used in the evaluation of RPN expressions.

22
Q

RPN↔infix - trees

A

Trees can be traversed in-order to obtain the infix and post-order to obtain the RPN (postfix).

23
Q

In-order traversal

A

Place a dot under each node. Trace around tree starting to left of root. As you pass underneath a node output its data.

24
Q

Post-order traversal

A

Place a dot on the right of each node. Trace around tree starting to left of root. As you pass to right of node output its data.

25
Q

Post-order Algorithm

A
  1. Traverse the left sub tree until there isn’t one. 2. Traverse the right sub tree (if there is one). 3. Re-visit the root of the current branch. 4. Repeat 1, 2, 3 until every node has been visited.
26
Q

In-order Algorithm

A
  1. Traverse the left branch until there is no left branch. 2. Visit the root of the current branch. 3. Traverse the right sub tree if there is one. 4. Repeat steps 1, 2 and 3 until every node has been visited.