Comp 2 Flashcards
What is single processor concurrency?
A processor that processes sequentially but can switch very quickly between processes hence giving an impression of parallel processing.
What is multiprocessor concurrency?
- Processes can be processed concurrently
- Programs are broken down into sub programs and places in a queue to avoid synchronisation problems.
Advantages and disadvantages of multiprocessor concurrency?
Advantages:
- Increased speed as more then one process can be process at a time
- Utilised in divide and conquer algorithm
- Less wait time for input/output operation as during relevant processes can be executed
Drawbacks:
- Difficult to identify where it can be implemented in a program
- Harder to debug and test as some errors are time related
What is the main difference between functions and procedures?
Functions return values where as procedures generally do not.
Advantages of functions/procedures?
- Less code needs to be written as no need to repeat code
- Easier to read and understand when monitoring and fixing code
What is a parameter?
A parameter is an variable passed to a function.
What does it mean to pass a variable by reference?
- ByRef means that when the variable is passed it is passed by reference from memory.
- Any changes made are saved to memory.
What does it mean to pass a variable by value?
- By value means that any changes made to variable in the function is not saved in memory
Describe the four types of abstraction?
Procedural: Breaking problems into sub-problems
Functional: Utilising in-built functions from library
Data: Isolation how data is created and how it behaves
Problem: Problems removed until it’s straightforward and simple.
Describe a repeat until loop.
A repeat until loop is always executed at least once.
At the end of the program the condition is tested and repeats until no longer true.
Compare recursive solution to a iterative solution.
- Recursive solutions have fewer variables
- Harder to understand making it harder to maintain
What is a variable?
A space in memory that holds a value which can be changed during the execution of the program.
What is a local variable?
Local variables are variables only available to the function they are coded in.
What is a global variable?
A variable that is available to the whole program.
Compare the use of global and local variables?
Global should only be used if there is use of value throughout program as otherwise it hard to trace and uses up memory unnecessarily.
Local variables are more memory efficient as only take up memory when used.
Easy to trace as it promotes modularity.
Advantages of modularity?
- Breaking down a problem into sub-programs saves development time as more than one person can work on it at a time.
- Debugging and testing easier as less time spent locating errors
- Programs are easier to understand and maintain.
- Any new features are easy to add.
What are declarative languages?
A language which expresses structure and logic of computation without control flow.
What is backtracking?
When a programmer searched different logical pathways until the correct one is found. Trial and error approach.
What is Heuristics?
Rule of thumb/educated guess approach which is used when unfeasible to analyse
all eventualities.
This leads to a “good enough” result
although it is not 100% reliable
What is pipelining?
Next instruction being fetched even though current instruction is not yet finished executing.
What is caching?
Commonly used instructions stored in fast memory storage. Web pages can be stored this way.
What are the benefits and drawbacks of caching?
+ Reduces execution time as data can be accessed faster.
+ Faster then RAM
- Can produce stale data.
- Very expensive
- Small compared to RAM
What does a precondition consist of?
Name:
Input:
Output:
Precondition:
What are the advantages of preconditions?
Documentation helps maintain and understand the code.
User can know the checks that need to carried out before subroutine is called.
Explain the Dijkstra algorithm.
1) Select a start node
2) Give start node a value of 0 and all other nodes a value of infinity.
3) Place nodes into a queue.
4) Remove start node and neighbour node.
5) startNode = u & neighbourNode= w
6) newDistance = distanceAtU + distanceUToW
if newDistance < distanceAtW
distanceAtW = newDistance
7) Queue changes to reflect this
Describe what is meant by recursion.
The function calls itself from within the function.
Explain advantages of using reusable components.
- Modules already tested so more
reliable programs. - Less development time as programs
can be shorter and modules can be
shared
What are the three types of modelling?
- Physical
- Process
- Mathematical
Explain Physical modelling.
Real life objects represented as scale models to see how they behave in certain situations