What is a parameter?
copy of a variable which is passed to a subroutine. Value of parameter only changes within the subroutine, doesn’t affect variable outside
diferences between linked list and array?
linked list is a dynamic data structure, array is static
In an array any element can be accessed directly -linked list needs to be traversed until element is found
What is 0(1)?
Constant
Algorithm will take same amount of time no matter its size.
Tell via no loop
What is 0(n) ?
Linear
Algorithm performance grows in linear time.
Tell via iteration e.g. for or while loop
What is 0(n^2)?
Polynomial
Algorithm performance related to square of data size.
tell via two nested loops.
What is 0(2^n)?
Exponential
Algorithm were time taken to execute doubles for each item added.
e.g. recursion
What is 0(logn)?
Logarithmic
Time taken grows very slow as data set size increases.
e.g. Binary search.
Usually tell through data halving
what is a linked list?
a dynamic data structure
each node consists of data and a pointer
pointer provides location of next node
pros of using a modular approach?
Easier to debug
Each area can be tested before integrating
Code can be reused
People can work in their expertise
Save time
depth first vs Breadth first?
Depth first:
Depth first goes to left child node. If no left child node goes to right child node.
When no child nodes left algorithm backtracks to parent node.
Uses stack structure
Breadth first:
Visits all nodes connected to start node
Then all nodes connected to each of those nodes and so on
Uses queue structure
How does depth first use backtracking?
When a node doesn’t have any nodes to visit
Algorithm goes back to previous visited node to check for further nodes
What is recursion?
when a subroutine calls itself from within itself
needs a finite stopping condition
what is caching?
storing instructions/data after theyve been used as may be used again. Saves time as don’t have to go back to secondary storage to retrieve.
Common in web pages
differences between global vs local variables?
global variables usually defined at beginning of program
global can be run by many functions
local variables usually used in a subroutine and don’t exist after subroutine is run
local variables may overwrite global variables
but 2 local variables in different subroutines won’t overwrite each over
What are the differences between passing a parameter by value and reference?
By Ref changes the value in variable
By ref passes the address
Byval only a copy of data is passed
ByVal change is lost when procedure ends
which sorting algorithms are 0(nlogn)?
quick sort
merge sort
faster for larger data sets
how to delete an item from tree?
find location of item
replace content of nude as ‘null’
make node pointing to item, point to the item which the null item was pointing to.
add item to the empty node list
how to add an item to a tree?
find the location of the item you want to connect the new item to
create a new node
add a pointer from the current item to the new item
change the pointer of the new item to null
similarities between trees and graphs?
both consist of nodes
both connected by edges
both dynamic data structures
How does the A* algorithm work?
using heuristics (an approximated cost from node x to the final node)
makes finding shortest path more efficient as less nodes have to be covered
How can a 1D array be used as a stack?
Array size must be defined
a stack pointer is used to point at top of array
When an item pushed - pointer incremented
When an item popped - pointer decremented
what is problem recognition?
identifying there is a problem to be solved
identifying what the problem is and how it is solvable by a computer e.g. finite solutions
what is performance modelling?
test the behaviour of a system before it is used
method of performance modelling?
stress testing
testing with large number of inputs
what are the differences between a graph and a tree?
a tree has a hierarchy (parent/child)
a tree has a root node
a graph can be directed/undirected
a graph can be weighted
why does recursion use more memory than iteration?
recursion creates new variables each time whereas iteration uses the same variables
similarities and differences between a record and a class?
record is a data structure
class is a template for making data structures
both can store multiple data types
both can have instances
both can have methods
what is concurrent processing?
concurrent processing is when two or more processes independant of each other can be executed at the same time, each task given a slice of processor time to look like tasks are being completed simultaneously.
how is dijkstras algorithm implemented?
a priority queue is used, shortest lengths at front of queue.
Uses weights
difference between A* algorithm and Dijkstras?
A* has two cost functions, actual cost and approximate cost.
A* doesn’t need to find all of the solutions
disadvantage of A* algorithm?
speed of algorithm is constrained by accuracy of heuristic
why is concurrent processing necessary?
larger number of requests -> server needs to respond within reasonable time
users could override each others changes -> so use record locking to stop.
☹️ could lead to deadlock where both don’t move as waiting on each other
why is decomposition necessary?
splits problem into smaller subproblems
smaller probs are more managable
smaller probs easier to solve
split tasks
Last changed6 months ago