Paper 2 Flashcards

1
Q

variable

A

named locations that store data in which the contents can be changed during program execution

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

local variable

A

declared inside a function. They can only be accessed and used in that function.

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

global variable

A

declared outside of all the functions, they can be used throughout the whole program including inside functions.

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

advantages of functions

A

easier to create and test

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

subprogram

A

self-contained units of code that perform some well-defined purpose.

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

function

A

a subprogram that ALWAYS returns a single value

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

procedure

A

a subprogram that returns one or many values.

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

parameter

A

the data that is supplied to a subprogram so that they can be reused

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

passing by reference

A

the address of the variable is passed to the subprogram.

if the variable is changed it stays changed.

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

passing by value

A

a copy of the variable is passed to the subprogram. The original variable is unchanged no matter what the subprogram does.

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

binary search precondition

A

the list needs to be sorted

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

Insertion sort

A

works by dividing a list into two groups: sorted and unsorted. Elements are inserted one by one into their correct position in the sorted section.

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

thinking abstactly

A

represents reality by recognising what is important and blocking out other details

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

thinking ahead

A

planning input and outputs e.g. caching

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

caching

A

a temporary store where data and instructions or data that are likely to be needed are stored.

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

Thinking procedurally

A

writing in modules to split a problem up into manageable tasks

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

Thinking Logically

A

inferring things from what you already know and understanding where decisions need to be made and their consequences

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

Thinking concurrently

A

thinking about how a job might be done better if some parts were performed at the same time.

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

features of an IDE

A
  1. Auto-complete
  2. colour coding/ syntax highlighting
  3. stepping
  4. breakpoints
  5. watch window
  6. error diagnostics
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

features of an IDE: Auto-complete

A

recognises identifiers

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

features of an IDE: colouring syntax

A

identifies different features making the code easier and quicker to check

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

features of an IDE: stepping

A

runs one line at a time to check the result, good for error checking

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

features of an IDE: breakpoints

A

stops the code at set points to check the value of variables, good for error checking

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

features of an IDE: watch window

A

tracks how variables change during the execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
features of an IDE: error diagnostics
locates and reports errors
26
IDE
Integrated Development Environment
27
What is an IDE
contains all the tools needed to write, develop and debug and program
28
IDE three main tools
1. editor 2. build facility (automates the process of constructing a program from its component parts) 3. a debugger
29
Three programming constructs
sequence selection iteration
30
sequence
a series of statements that are executed one after the other
31
selection
a decision is made based on the state of a boolean expression
32
Iteration
where a section of code is repeated
33
Selection cause
IF statement/ CASE statement | branch in assembly
34
Iteration cuase
FOR loop / WHILE loop / REPEAT UNTIL loop
35
repeat until loop
Condition tested at the end of the loop
36
While loop
condition tested at the start of the loop
37
for loop
countrolled - repeats a set number of times
38
Recursion
A procedure calls itself. alternative way of producing iteration. causes stack overflow is no terminating condition is built in.
39
Source code
The code written by the user
40
Compiler
translates high level language. | produces an object-code file. This can be run directly from the operating system,
41
Interpreter
Translates high level language. | translates and executes the program line by line.
42
Modularity
separates the programs functionality into independent, interchangeable modules.
43
constant
named locations that store data in which the contents stay the same during program execution
44
object orientated programming
allows a program to solve problems by programming objects which interact with each other.
45
class
a template used to define an object. It specifies the methods and attributes an object should have.
46
object
an instance of a class
47
method
a subroutine associated with an object
48
new
a specific method called a constructor
49
constructor
a method that defines how an object is created
50
attribute
variables contained within and associated to an object
51
Encapsulation
ensuring private attributes can only be amended through public methods. Stops attributes being manipulated in unintended ways.
52
inheritance
the ability for a class to inherit the methods and attributes of a parent class. The child class can have its own methods and attributes and override the inherited methods and attributes.
53
polymorphism
the ability for objects of different classes to be treated in the same way.
54
polymorphism example
the same method may be applied to objects of different classes
55
overriding
The method in the child class can be different to the method in its parent class whilst still having the same name and parameters etc
56
examples of abstraction
- variables - objects - layers - data structures - entity-relation diagrams
57
well-defined problems
problems that are clear to understand and the solution has defined expectations.
58
ill-defined problems
messy problems which are not clear how to solve.
59
Stages of problem solving
1. Understand the problem 2. Devise a plan 3. carry out the plan 4. Review your work
60
Why do algorithms help
- helps understand the problem - executed more quickly - possible to resort to trial and error
61
problem recognition
The ability to recognize and acknowledge that an issue exists or that a situation needs attention in an existing process or program. The ability to define a problem and know exactly what it is.
62
Computable
a problem is computable is we can come up with an algorithm that will solve every instance of the problem in a finite number of steps.
63
intractable problem
a problem which cannot be completely solved.
64
problem decomposition
the process of taking a big problem and breaking it down into smaller problems until you fully explored the problems. Each of these smaller problems translate into one task which is more easily programmable as an individual module, function or procedure.
65
Top-down Problem solving
an approach to solve a problem that involves breaking down the main problem into sub-problems.
66
divide and conquer
a technique based around reducing the size of a problem with successive iterations. You look at a problem, apply some rules and discard any data that does not match then repeat the process with any information which is left. E.g. binary search.
67
divide and conquer advantages
- efficient | - short runtime
68
linked list
ordered data structure that uses pointers to sort and order the data items
69
linked list node two parts
1. to store the actual data | 2. to store the reference to the next node
70
benefits of linked lists
efficient at adding/removing data
71
drawbacks of linked lists
slow to search
72
adding data to linked lists
- input the data in the location indicated to by the free storage pointer - update the free storage pointer to next free location - update the pointer for the new node to point to the next free storage spot
73
removing data from linked lists
- find the data item you want to delete - update the previous pointer to point to the next data item - the node for the deleted item can be added to the free storage list
74
Trees
Hierarchical data structure with data related to the data above it in the tree
75
Binary tree
tree structure where each node can only have 0,1 or 2 child nodes
76
What doe each node contain in a tree?
- pointers to the next data items | - data
77
preorder
- start at root node - traverse the left sub tree - traverse the right subtree
78
inorder
- traverse the left sub-tree - visit the root - traverse the right sub tree
79
postorder
- traverse the left sub-tree - traverse the right sub-tree - return to the root node
80
preorder dot
left
81
postorder dot
right
82
inorder dot
under
83
what does preorder do
selects roots before leaves
84
what does inorder do
sorts the nodes
85
what does postorder do
slects leaves before roots
86
graph
a set of edges/arcs connecting vertices/nodes
87
digraph
has one or more edges that have an arrow indicating you can only go in one direction
88
thinking ahead example process
- what answers do we need? | - What do we need to know to get what we need?
89
Thinking procedurally process
- divide the problem into sub-problems - do solutions already exist for any of the sub-problems - how do the sub-problems interact with each other
90
Backtracking
the process of incrementally building up towards a solution, abandoning a partial success when the solution can’t be completed and then going back to a previously successful match.
91
When does a backtracking algorithm end
when there are no more possible solutions to the first problem
92
backtracking advanatges
more effective than brute force as a large number of solutions can be eliminated with a single test
93
concurrent programming
where one computation advances without waiting for all the other computations to complete.
94
data mining
where vast amounts of unconnected data is searched through, patterns are found and correlations are calculated. There may be no predetermined matching criteria and a brute force approach may be used (alot of processing power)
95
Uses of data mining
- targeting ads/marketing campaigns - Anticipating resource demands - Detecting fraud and cybersecurity issues - Finding connection between seemingly unconnected events
96
positives of data mining
- improves marketing - improves the estimate of stock quantities - ensure demands are met - increase sales
97
negatives of data mining
- alot of processing power required - privacy concerns - misuse of information - inaccurate data can cause a negative effect
98
Big data
very large amounts of data on a particular topic
99
Parallel Computing
algorithm tasks are executed concurrently on a cluster of machines or supercomputers, is fundamental to managing big data tasks
100
Heuristics
making use of experience to find an acceptable solution, for example, using ‘rules of thumb’, educated guesses, intuitive judgements or common sense.
101
how are heuristics derived
derived from previous experiences with similar problems.
102
Why are Heuristics used/ what is the solution like?
Heuristic methods are used to rapidly find a solution that is ‘good enough’, even though it might not be the optimal solution.
103
Heuristic method example
when analysing data only analyse and gather the data which is most likely to help
104
performance modelling
process of carrying out mathematical approximations of how well models perform
105
What does performance depend upon
complexity
106
performance modelling example
- how efficient a program is | - whether a computing can cope with the strain
107
pipelining
the process of taking a task and splitting it into smaller tasks and then overlapping the processing of each sub task to speed up the overall process.
108
pipelining example
the fetch decode execute cycle: For example, when one instruction is being fetched, another instruction is being decoded and the last is being executed.
109
Visualisation
The ability to picture a problem and its solution in a visual way. It is easier to understand structures in a visual way
110
Visualiation example,
flow diagrams
111
5 methods of problem solving
1. enumeration 2. simulation 3. theoretical approach 4. trial and error 5. creative solution
112
enumeration (method of problem solving)
Designing an algorithm that performs an exhaustive search
113
enumeration example
find the solution to an anagram by testing every permutation of letters
114
simulation (method of problem solving)
The process of designing a model of a real system in order to understand the behavior of the system, and to evaluate various strategies for its operation
115
simulation examples
- Financial risk analysis - Amusement park rides - Population predications - Managing inventory systems - Queueing problems
116
Theoretical approach (method of problem solving)
the problem be broken down into pure theory and be represented by mathematics
117
Trial and error (method of problem solving)
If you don’t know how to solve a problem using trial and error may help the process/ completely solve the problem depending on its complexity.
118
creative solution (method of problem solving)
Finding a solution to a problem which doesn’t follow the expected algorithms and rules but still provides an alternative solution
119
Stack
Last in First Out data structure
120
Queue
First in First Out data structure
121
How do stacks work
- data is push to the top of the structure | - data is popped from the top of the structure
122
stack pointers
a single pointer points to the top of the tack and increments/decrements as data is added/removed
123
algorithm for PUSHING onto a stack
``` IF stack pointer = max THEN report stack full ELSE set stack pointer = stack pointer + 1 set stack[stack pointer] = data END IF ```
124
algorithm for POPPING off a stack
``` IF stack pointer = min THEN report stack empty ELSE set data = stack[stack pointer] set stack[stack pointer] = null set stack pointer = stack pointer -1 END IF ```
125
How do Queues work
- data is pushed to the end of the structure | - data is popped from the start of the structure
126
Queue pointers
two pointers one pointing to the start the other pointing to the end. both increment as data is added/removed.
127
circular queues
the newest data to be added in stored in the location which is vacated by popped data at the start of the queue
128
algorithm for PUSHING onto a queue | not circular
``` IF start pointer =1 and end pointer = max THEN report queue full ELSE set queue (end pointer + 1) = data set end pointer = end pointer + 1 END IF ```
129
algorithm for PUSHING onto a queue | circular
``` IF start pointer =1 and end pointer = max THEN report queue full ELSE IF start pointer = end pointer +1 THEN report queue full ELSE set queue (end pointer + 1) = data set end pointer = end pointer + 1 END IF ```
130
algorithm for POPPING off a queue
``` IF start pointer = 0 THEN report queue empty ELSE set data = queue [start pointer] set start pointer = start pointer - 1 ```
131
computational thinking
Thinking about how a problem can be solved through formulating the problem and constructing the algorithm to solve it.
132
Abstraction within programming / why is it abstraction
programmers use high level language commands. | The complexity of the machine code behind it has been removed
133
advantages of thinking ahead/ preconditions
- the user knows what they have to do - makes clear documentation easier to maintain - user can be confident that necessary checks have been carried out
134
benefits of caching
instructions and data can be fetched alot quicker
135
drawbacks of caching
- algorithms choosing which data to be cached my chose wrong data - if algorithms are inefficient it can make the performance worse
136
advantages of thinking concurrently
- increased program throughput | - time is never wasted on user input
137
disadvantages of thinking concurrently
- if too many programs are running it takes a long time to process
138
Advantages of recursion
- suited to some problems (some functions are naturally recursive) - reduces the size of the problem (divide and conquer)
139
Disadvantages of recursion
- can run out of stack space due to too many function calls which causes stack overflow - more difficult to trace - requires more memory than iteration - slower than iteration
140
Breakpoints
a set point which stops the program at that line
141
step through
executes each line of code when you click
142
purpose of testing
uncovered undetected errors
143
procedural programming examples
Python, Pascal, Basic
144
Object orientated examples
Java, Delphi, C+
145
Instantiation
The creation of a new object
146
Complexity
how well the performance of an algorithm scales as the size of data sets increase.
147
time complexity
the number of steps/line of code executed in an algorithm.
148
space complexity
the memory requirement for an algorithm
149
efficiency
time complexity and space complexity
150
BigO
a complexity notation. remove all coefficiants and just write the value of n with the largest exponent e.g. O(n)
151
O(1)
constant complexity
152
constant complexity
An algorithm that always executes in the same time regardless of the size of the data set. Best Algorithms.
153
O(log n)
Logarithmic Complexity
154
Logarithmic Complexity
An algorithm that halves the data set in each pass. Efficient with large data sets. Good algorithms.
155
O(n)
Linear Complexity
156
Linear Complexity
An algorithm whose performance is proportional to the size of the data set and declines as the data set grows. Fair algorithms.
157
O(n^a)
Polynomial complexity (quadratic, cubic etc)
158
Polynomial complexity (quadratic, cubic etc)
An algorithm whose performance is proportional to the square of the size of the data set. Significantly reduces efficiency with increasingly large data sets. Poor algorithms.
159
O(2^n)
Exponential Complexity
160
Exponential Complexity
An algorithm that doubles with each addition to the data set in each pass. Inefficient. Extremely poor algorithms that should be avoided.
161
O(n log N)
Algorithms that divide a data set but can be solved using concurrency on independent divided lists.
162
complexity order
O(1) -> O(logn) -> O(n) -> O(nlogN) -> O(n^2) -> O(2^n)
163
Linear search best
O(1)
164
linear search average
O(n)
165
linear search worst
O(n)
166
binary search best
O(1)
167
binary search average
O(logn)
168
binary search worst
O(logn)
169
Binary search tree best
O(1)
170
Binary search tree average
O(logn)
171
Binary search tree worst
O(n)
172
Hashing best
O(1)
173
Hashing average
O(1)
174
Hashing worst
O(n)
175
Breadth/Depth first best
O(1)
176
Breadth/Depth first average
O(V+E) V = no. vertices E = no edges
177
Breadth/Depth first worst
O(V^2)
178
Bubble sort best
O(n)
179
Bubble sort average
O(n^2)
180
Bubble sort worst
O(n^2)
181
Bubble sort space complexity
O(1)
182
Insertion sort Best
O(n)
183
Insertion sort Average
O(n^2)
184
Insertion sort Worst
O(n^2)
185
Insertion sort Space complexity
O(1)
186
Merge sort best
O(nlogn)
187
Merge sort average
O(nlogn)
188
Merge sort worst
O(nlogn)
189
Merge sort Space complexity
O(n)
190
Quick Sort best
O(nlogn)
191
Quick Sort average
O(nlogn)
192
Quick Sort Worst
O(n^2)
193
Quick sort space complexity
O(logn)
194
how to get the bigO expression
- remove all terms except the one with the largest exponent | - remove all constant factors
195
linear search
starts at the beginning of a list and checks each item in turn until the desired item is found
196
Binary search
divides a list in two each time until the item being searched for is found
197
Four sorting algorithms
Bubble, Insertion, Quick, Merge
198
Insertion sort words
Make the first item in the list the sorted list. The remaining items are the unsorted list. While there are items in the unsorted list take the first item of the unsorted list. While there is an item to the left of it which is smaller than itself swap with that item. End while. The sorted list is now one item bigger. End while
199
Merge sort
splits a list of size n into n lists of size 1. Each pair of lists are merged together in order until there is only one list of size n.
200
Why does merge split down into unit lists
because a list of length one is sorted
201
Merge algorithm
1. If the sub-list is 1 in length, then that sub-list has been fully sorted 2. If the list is more than 1 in length, then divide the unsorted list into roughly two parts. (An odd numbered length list can't be divided equally in two) 3. Keep dividing the sub-lists until each one is only 1 item in length. 4. Now merge the sub-lists back into a list twice their size, at the same time sorting each items into order 5. Keep merging the sub-lists until the full list is complete once again.
202
Quick Sort Algorithm
1. If the list to be sorted is length 1, then finish - job complete 2. Pick an item within the list to act as a 'pivot'. The left-most item is a popular choice. 3. Split the list into two parts - one list with items equal to or larger than the pivot item and the other list contains items smaller than the pivot 4. Repeat this process on the two halves
203
Quick sort
The basic idea is to keep splitting a list into two smaller lists, sort those lists using the same quick-sort rules, then split the sub-lists and sort again, until there are only lists of 1 item or less left.
204
Where can the pivot be applied
The pivot can be applied to any item in the unsorted list.
205
advantages bubble
- simple
206
disadvantages bubble
- long time to run
207
advantages insertion
- Simple to code - Good performance with small lists - memory efficient - good with sequential data
208
disadvantages insertion
- poor performance with larger lists | - not as quick as merge/quick sort
209
disadvantages quick
- difficult to implement - if a bad pivot is picked the runtime is slow - worst case efficiency is bad
210
advantages quick
- very efficient | - no additional storage required/ less stack memory
211
advantages merge
- Good for sorting slow access data - Good for sorting sequential data - if there are two equal values then positions are conserved, which is quicker
212
disadvantages merge
- It needs twice then length of memory space than the list - If recursion is used, it used twice the stack memory as a quick-sort - quick sort is faster
213
advantages Linear search
- Good Performance - List does not need to be ordered - Not affected by insertions and deletions
214
disadvantages linear search
- May be too slow over large lists
215
advantages binary search
- Works well with larger lists | - Quicker
216
disadvantages binary search
- Small lists simpler to use linear search | - Cannot deal with unordered lists
217
Depth first traversal
- uses a stack to store the visited nodes - visits all the nodes attached to a node connected to a starting node before visiting a second node attached to a starting node
218
Depth first Algorithm
``` PUSH first node onto stack mark as visited Repeat visit the next uninvited node adjacent to the node on top of the stack mark as visited PUSH this node onto the stack if no node to visit POP node off the stack UNTIL stack is empty ```
219
Breadth first Traversal
- uses a queue to store the visited nodes | - visit all the nodes attached directly to a starting node first
220
Breadth first algorithm
``` PUSH first node into the queue mark as visited REPEAT visit unvisited nodes connected to the first node PUSH nodes into the queue UNTIL all nodes visited REPEAT POP next node from queue REPEAT visit unvisted nodes connected to current node PUSH nodes onto queue UNTIL all nodes visited UNTIL all nodes visited ```
221
Shortest path algorithms
Dijkstra's and A*
222
Dijkstras table columns
visited, vertex, shortest distance from start node, previous vertex
223
What are all the shortest distances filled with at the beginning (Dijkstras)
infinity, except for the vertex your measuring from which is zero
224
Dijkstras
Finds the shortest distance between one node and any other node in a network
225
A*
A variation of Dijkstras that uses a heuristic to try and get the correct solution sooner
226
A* table
visited, vertex, shortest distance from start node, heuristic distance, sum, previous vertex
227
Advanatges of Dijkstras
- doesn't need to know the target node before | - good for multiple target nodes
228
Disadvanatges of Dijkstras
- doesn't work for negative edge weights | - slower than A*
229
Advantages of A*
- faster - always find a solution if it exists - can be morphed into other path finding algorithms by changing the heuristic
230
Disadvanatges of A*
- no good if you have many target nodes | - not good if you have no prior knowledge of the network
231
time complexity vs performance
even if the complexities are the same one algorithm may still perform better than another
232
Why are linked lists good for ordering list?
- dynamic data structure allows data to be added/removed | - data can be added/deleted from any point in the list
233
advantages of subprocedures
- can split between programmers (can specialize in their areas) - speeds up completion time (multiple procedures are worked on concurrently) - Easier to maintain/ test (can test each module invidiually) - reuse modules saving time
234
What does depth first traversal use?
stack
235
What does breadth first traversal use
queue
236
Depth first traversal words
Depth-first goes to left child node when it can if there is no left child it goes to the right child when there are no child nodes the algorithm ‘visits’ it’ and backtracks to the parent node.
237
Breadth first traversal words
first visits the root. Breadth-first visits all nodes connected directly to start node then visits all nodes directly connected to each of those nodes (and then all nodes directly connected to those nodes and so on…)
238
how is backtracking used in depth first traversal
when there are no nodes to visit the algorithm goes back to the previous node to check for further nodes to visit
239
process of decomposition
splitting a problem down into its component parts
240
for loop pseudocode
for i=0 to 7 print(“Hello”) next i
241
while loop pesudocode
while answer!=”computer” answer=input(“What is the password?”) endwhile
242
do until loop pseudocode
do answer=input(“What is the password?”) until answer==”computer”
243
MOD
gives the remainder of a division
244
DIV
integer division (rounds down)
245
if/else Pseudocode
``` if/else if entry==”a” then print(“You selected A”) elseif entry==”b” then print(“You selected B”) else print(“Unrecognised selection”) endif ```
246
switch/case pseudocode
``` switch/case switch entry: case “A”: print(“You selected A”) case “B”:1 print(“You selected B”) default: print(“Unrecognised selection”) endswitch ```
247
get the substring
stringname.subString(startingPosition, numberOfCharacters)
248
by default how are parameters passed?
by value
249
reading from a file
myFile = openRead(“sample.txt”) x = myFile.readLine() myFile.close()
250
writing to a file
myFile = openWrite(“sample.txt”) myFile.writeLine(“Hello World”) myFile.close()
251
procedure OO pseudocode
public procedure setAttempts(number) attempts=number endprocedure
252
Inheritance OO pseudocode
class Dog inherits Pet attributes methods endclass
253
create an instance of a class OO
objectName = new className(parameters)
254
COmputable
if we can come up with an algorithm that will solve every instance of the problem in a finite number of steps it is computable.
255
Intractable problem
A problem that cannot be completely solves
256
Methods of problem solving:
- Enumeration - Simulation - Theoretical approach - Trial and error - creative solution
257
problem recognition
The ability to recognize and acknowledge that an issue exists or that a situation needs attention in an existing process or program. The ability to define a problem and know exactly what it is.
258
Problem decomposition
the process of taking a big problem and breaking it down into smaller problems until you fully explored the problems. Each of these smaller problems translate into one task which is more easily codeable as an individual module, function or procedure.
259
Thinking ahead
planning inputs and outputs which may be used in a computer program.
260
Thinking procedurally
Dividing a problem into a series of sub problems are tackling each problem individually. Some will already have solution written which you can copy.
261
Thinking logically
inferring things from what you already know. Understanding where a decision needs to be made and knowing its consequences.
262
benefits of caching
- speeds up access times and therefore improves performance - uses less physical resources - increases throughput
263
drawbacks of caching
- it may not store the correct data, the data may no longer be relevant - very complex trying to deal with data to be cached - the physical memory is expensive
264
Why are reusable program components good?
- saves time and memory | - saves memory space
265
three types of error
- logical error - systematic error - run time error
266
logical error
An error that causes the program to perform something unintended
267
systematic error
Statement that break the rules of the programming language
268
run time error
Error that occurs due to an unexpected event/causes | the program to stop working (crashes)
269
advantages of writing in modules
- Work can divided between a team, saves time as work takes place in parallel - each team must only know what values to go into their subroutine and their expected functionality - breaks problem down, easier to understand/test/debug/read - Modules can be given to teams with specific expertise - each subroutine can be tested individually before its combined to the main program - code can be reused
270
scope
The section of code where a variable can be accessed and used
271
local variables with the same name as global variables...
overwrite/ take precedence of global variables
272
modular design
program is split into self contained tasks which can be written and tested individually. Modules can be subdivided into smaller modules.
273
concatination
joining two strings together
274
Benefits of using recursion over iteration
- more natural to read - Quicker to writes/ less lines of code - Some functions are naturally recursive - can reduce the size of the problem with each call
275
Drawbacks of using recursion over iteration
- can run out of stack space (due to too many function calls, causes it to crash) - more difficult to trace/follow as each frame on the stack has different variables - requires more memory - Usually slower than iterative methods due to stack maintenance
276
Why are global variables sometimes used
When a variable needs to be accessed throughout the whole program and not just in one subroutine. e.g. a date variable
277
Why is the use of global variables usually avoided
- makes it difficult to integrate modules - increases the complexity of a program - easy to change the value by accident, leading to errors
278
non user defined function examples
int, input, print
279
function (inline)
a named section of code that performs a specific task and always returns a value.
280
what is more common: functions or procedures
function
281
Example rules for writing functions
- only allow functions to be of a certain length - Suitably named variables - functions must have a single entrypoint - no/ few global varaiables