2.2.1 - programming techniques Flashcards

11 (54 cards)

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.

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

global variables

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

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

modular programming

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
binary search
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
binary search pseudocode
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
bubble sort
* 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
bubble sort pseudocode
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
insertion sort
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
insertion sort pseudocode
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
breakpoint
Allows the program to be stopped at a predetermined point in order to inspect its state.
32
step-through
Allows the programmer to watch the effects of each line of code.
33
watch
Code can be examined as it is running which allows logical errors to be pinpointed.
34
crash dump
Shows the state of variables at the point where an error occurs.
35
disadvantages of global variables
- 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
Why is parameter passing to a function a better alternative to global variables?
Only a copy of the data passed may be changed so no unforeseen errors will occur in other modules.
37
recursion
When a function calls itself from within the function.
38
parameter
An item of data passed into a subroutine when it is called that is used as a variable in the subroutine.
39
procedural programming language
A high-level language that gives a series of instructions in a logical order.
40
scope
A procedure that the variable is valid for.
41
scope in relation to global and local variables
A local variable takes precedence over a global variable of the same name.
42
4 similarities between graphs and trees
* Both consists of nodes * Both are connected by edges/links * Both are non-linear data structures * Both are dynamic data structures
43
4 differences between graphs and trees
* Tree is 1-directional whereas a graph is 2-directional * Tree has a root node whereas a graph does not have a (clear) root node * Tree will not have cycles whereas graphs can contain cycles * Tree will not be weighted whereas edges in a graph can be weighted
44
Explain the difference between branching and iteration.
 Branching decides which code is run / only runs code once  Iteration repeatedly runs the same code in the same sequence
45
benefits of using iteration instead of recursion
 The program can/might run faster  Cannot run out of stack space/memory  Easier to trace/follow
46
disadvantages of using iteration instead of recursion
 Iteration can lead to lengthier code  Iteration can lead to code that looks more complex / is harder to understand  some problems are more elegantly coded with a recursive solution
47
Why are reusable components used in programs?
* One piece of code can be used many times / in multiple places / makes code more efficient * No need to write the same code multiple times * Takes less time to plan/design/code the program * Easier error detection as fix once and it corrects in each place // less likely to have errors as code is not written multiple times * Makes it easier to maintain the program
48
syntax highlighting
to identify key words, variables and help identify syntax errors
49
auto-complete
start typing a command/identifier and it completes it
50
benefits of oop rather than procedural
* Code can easily be reused… * …classes can be used in other programs * …inheritance can be to extend upon existing classes * …as a class can be based on an existing class * Easier to maintain…. * ….as classes can be modified or extended * …debugging can be easier as encapsulation limits how attibutes are changed. * Code can be more secure… * … as access to attributes can be restricted to being via methods. * Better for coding as part of a team… * …as classes can be distributed between team members.
51
disadvantages of global instead of local
* Increases memory usage (as it is used until full program execution is over) * Alterations within the function may have unwanted side effects elsewhere in the program.
52
advantages of global instead of local
* Variable doesn’t need passing as a parameter (byref) * You don’t need to return a value * Can be accessed from any function / anywhere in the program
53
state one way directed graph different from undirected
In directed arcs/edges may only go in 1 direction
54
difference between do and while loop
* While loop will check the condition at the start of the loop // pre-condition loop * Do loop will check the condition at the end of the loop // post-condition * The code in a while loop may never run (if the condition is already met) * The code in a do loop will always run at least one.