Lecture 1 - Time Complexity Revision Flashcards
What is time complexity?
A function of input size, denoting how long the algorithm will run for. We typically look at the worst-case of an algorithm.
Why do we use the worst-case of an algorithm?
Since worst-case provides a gurantee on algorithm’s performance.
What is asymptotic behaviour ?
Behaviour of never-ending input. It is a mathematical concept.
What are the Big-Oh functions?
f(n) = O(g(n)) and f(n) <= cg(n)
What does the Big-Oh function f(n) = O(g(n)) mean?
That the function f grows no faster than function g.
In Big-Oh which function is well know ?
g(n) e.g. O(n)
In Big-Oh which function is not known precisely?
f(n)
What do we need to remember when working with Big-Oh?
To always bind tightest, even if greater functions are valid. E.g. if O(n^2) is valid, then so is O(n^3) and so on, but we would still use O(n^2), since it binds the tightest.
What is Big-Oh ?
Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity.
What can x = logaN be (where a has a power)?
n = a^x
Log properties to remember?
- log mn = log m + log n
- log m/n = log m - log n
- log n^c = c log n
Are logs of different bases related, how so ?
Yes, these are related by a constant factor. This is done by taking the same log of both sides and simplifying.
Solve x = logaN, by taking logs of both sides.
x = logaN
logbN= logb A^x
logbN = X log A
since x = logaN we get logbN = logaN * logbA
c = logbA is a consant , since both b and a are constants
logbN = clogaN
this gives O(logn)
What is polynomial time?
O(n^c)
What is exponential time?
O(c^n)