Week 1 Flashcards
Give examples of real-world applications of algorithms
- Analysis of Big Data (machine learning algorithms)
- Social media (algorithmic marketing)
- online shopping (recommendation systems)
- Stock market (high-frequency trading algorithms)
- Search engines
Give the formal definition of an algorithm
An algorithm is a sequence of steps for performing a task in a finite amount of time
What does it mean that an algorithm runs in a finite amount of time?
That when we run the algorithm with input data, it should always stop.
What is the mathematical definition of an algorithm?
A Turing Machine
What do we use data structures for in regards to computational algorithms?
We use data structures to store, access and manipulate data in computational algorithms
What is the definition of a good algorithm?
Algorithms which:
- utilise efficient data structures
- are formally correct in terms of providing the correct solution according the problem spec
- efficient in terms of speed and resources
What are our three interests in regards to algorithm analysis?
- Primary interest: Running time/time complexity
- Secondary interest: space (memory) usage
- third interest: optimality of the output solution
What are the two types of analysis?
- Experimental
- Theoretical
What is experimental analysis of algorithms?
Analysis where we’re interested in the dependency of the running time on the size of the input.
What is the size of the input in experimental analysis?
The amount of memory you need to use in order to represent your data in the computer
What does experimental analysis involve?
Running our algorithm on input data designed for the purpose of testing it.
- This requires a good choice of sample inputs and an appropriate number of tests for statistical certainty
What does running time depend on in algorithms?
It depends on both the size and instance of input and the algorithm used as well as the software and hardware environment on which it runs.
Why might 3 different instances of inputs with the same size run through the same algorithm have varying running times?
This could be because those instances might be of varying difficulty or structural appearance.
- for example a for loop might be used in the algorithm and some input may qualify to evoke the for loop but others may not, despite being the same size of input
In experimental analysis what do we do when we have multiple instances of running time for the same input size?
We record the average running time of those instances (find the mean)
What are the potential drawbacks of experimental analysis
- they are performed on a limited set of test inputs (some problems may have infinite possible inputs so it would be impossible to test them all) so we must choose representatives of the set of input instances
- it requires all tests to be performed using the same hardware and software which is time consuming
- it requires implementation and execution of algorithms which is time consuming
What are the benefits of theoretical analysis?
- can take all possible inputs into account simultaneously (by abstracting from those objects). For example, we do analysis for all inputs of a fixed size n
- can compare efficiency of multiple algorithms independent of hardware/software environments
- No implementation is needed
How do we characterise the running time of an algorithm in theoretical analysis?
We represent the algorithm’s run time with a function f(n) where n is the non negative input size
List common run time functions and their names in order of slowest to fastest
n - linear
log(n) - logarithmic
n^2 - quadratic
n*log(n), - sorting runtime
n^5 - polynomial
2^n - exponential
What type of run time is the most efficient to scale with input size
Polynomial run times are the most efficient to scale with input size
What do we need to perform formal theoretical analysis
- A formal language to describe algorithms (so it can be acted upon in a certain way and used to implement a solution if)
- a computational model in which algorithms are executed
- a metric for measuring running time
- a way of characteristing running time
What is pseudo code?
- a high level description language for defining algorithms
- it provides a more structured description of algorithms
- allows for high level analysis of algorithms to determine their running time and space requirements
What are the steps for finding the minimum element of a set of numbers, stored in an array A
- set the minimum to the first element of array A
- loop through the elements of array A for j to the length of array A
- compare the current minimum to the element in the value of the current index in the list
- if this is smaller, store it in the variable holding the minimum
- once all elements in the list have been looped through, return the minimum value.
describe pseudocode
- is a mixture of natural and high-level programming languages
- describes a generic implementation of data structures or algorithms
- include expressions, declarations, variables initialisation and assignments, conditionals, loops, arrays and method calls.
Describe the computational model we’re abiding by
- typically found on a modern day computer
- CPU connected to a bank of memory cells, CPU can access memory
- each memory call can store a number, character or address
- we use random access machines which can address every single memory cell in the bank of memory in constant time
What is reaching a specific cell counted as in Random access machines
counted as one single primitive operation performed in constant time.
What is unit time?
An abstraction for saying how many seconds it takes
What are examples of primitive operations and an assumption about them?
- single addition, multiplication, comparison are all examples
- assumption is they require constant time to perform
How do we analyse run time of an algorithm in theoretical analysis?
We count the number of operations executed during the course of the algorithm