2.2.1 - programming techniques Flashcards

11

1
Q

algorithm

A

A set of rules or a sequence of steps specifying how to solve a problem.

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

variables

A

Identifiers (names} given to memory locations whose contents will change during the course of the program.

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

2 reasons why variable names should be standardised

A
  • makes the program easy to follow and update when required.
  • leaves less room for errors and
    inconsistencies in the names in a large program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

3 basic programming constructs

A
  • sequence
  • selection
  • iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

define sequence

A

just two or more statements executed one after the other

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

define selection

A

used to select which statement will be executed next, depending on some
condition

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

iteration

A

involves performing a
loop in the program to repeat a number of statements

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

3 types of loops

A
  • while…endwhile
  • repeat…until
  • for…next
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

integrated development environment (IDE)

A

A single program used for developing programs made from a number of components.

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

compiler/ interpretor

A

Translates high level code into machine code.

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

3 IDE tools to spot logic errors

A
  • breakpoint
  • watch
  • step through
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

subroutine

A

A named block of code which performs a specific task within a program.

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

2 types of subroutines

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

function

A

A named section of a program that performs a specific task. Returns a value.

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

procedure

A

Performs a task but doesn’t return a value.

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

by value

A

A copy of the variable is passed to the subroutine. Changing a parameter inside the subroutine will not affect its value outside the subroutine.

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

by reference

A

The memory location of the variable is passed to the subroutine. If it is changed in the subroutine, its value in the main program will also change.

18
Q

global variables

A

Declared in the main program and can be used anywhere in the program, including subroutines.

19
Q

local variables

A

Can be used within the subroutine and exist only during the execution of the subroutine. Cannot be accessed outside the subroutine.

20
Q

modular programming

A

The process of subdividing a computer program into separate sub-programs.

21
Q

advantages of subroutines

A
  • Small so relatively easy to understand, debug and maintain.
  • Can be tested independently.
  • Can be reused indifferent programs or parts of the same program.
  • Programmers can work on different subroutines.
  • A large project becomes easier to monitor and control.
22
Q

2 searching algorithms

A
  • linear search
  • binary search
23
Q

linear search pseudocode

A

function LinearSearch(alist,itemSought}
index = -1
i = 0
found = False
while i < length(alist) and found = False
if alist[iI = itemSought then
index = i
found = True
endif
i = i + 1
endwhile
return index
endfunction

24
Q

linear search

A

If the items are not in any particular sequence, the data items have to be searched one by one until the required one is found or the end of the list is reached.

25
Q

binary search

A

The algorithm works by repeatedly dividing in half the portion of the SORTED data list that could contain the required data item. This is continued until there is only one item in the list.

26
Q

binary search pseudocode

A

function binarySearch(aList, itemSought}
found = False
index = -1
first = C
last = len (aList)-1
while first <= last and found = False
midpoint = Integer part of ((first + last)/2)
if aList[midpoint) = itemSought then
found = True
index = midpoint
else
if aList(midpoint) < itemSought then
first = midpoint + l
else
last = midpoint - i
endif
endif
endwhile
return index
endfunction

27
Q

bubble sort

A
  • Go through the array, comparing each item with the one next to it. If it is greater, swap them.
  • The last element of the array will be in the correct place after the first pass
  • Repeat n-2 times, reducing by one on each pass the number of elements to be examined
28
Q

bubble sort pseudocode

A

numItems = len(numbers)
for i = 0 to numItems - 2
for j = 0 to(numItems - i - 2)
if numbers [j] > numbers [j + 1]
temp = numbers[j]
numbers [ j ] = numbers[ j + 1]
numbers [j+1] = temp
endif
next j
print (numbers)
next i

29
Q

insertion sort

A

The algorithm takes one data item
from the list and places It in the correct location in the list. This process is
repeated until there are no more unsorted data items in the list.

30
Q

insertion sort pseudocode

A

procedure inaertionSort(alist)
n = len(alist)
for index = 1 to n - 1
currentvalue = alist[index]
position = index
while position > 0 and alist[position - l| >
currentvalue
alist(position] = alist[position - 1]
position = position - l
endwhile
alist(position) = currentvalue
next index
endprocedure

31
Q

breakpoint

A

Allows the program to be stopped at a predetermined point in order to inspect its state.

32
Q

step-through

A

Allows the programmer to watch the effects of each line of code.

33
Q

watch

A

Code can be examined as it is running which allows logical errors to be pinpointed.

34
Q

crash dump

A

Shows the state of variables at the point where an error occurs.

35
Q

disadvantages of global variables

A
  • they make it difficult to integrate modules
  • they increase the complexity of a program
  • may cause conflicts with names in other modules
  • may be inadvertently changed when a program is complex
36
Q

Why is parameter passing to a function a better alternative to global variables?

A

Only a copy of the data passed may be changed so no unforeseen errors will occur in other modules.

37
Q

recursion

A

When a function calls itself from within the function.

38
Q

parameter

A

An item of data passed into a subroutine when it is called that is used as a variable in the subroutine.

39
Q

procedural programming language

A

A high-level language that gives a series of instructions in a logical order.

40
Q

scope

A

A procedure that the variable is valid for.

41
Q

scope in relation to global and local variables

A

A local variable takes precedence over a global variable of the same name.