Week 01
Week 01
I In-person lectures
I Live lecture recordings available on blackboard later
I Tutorials in labs
I One in-class test, one coursework
I Worth 50% each
I Need to score at least 30 in each and at least 40 on
average
What is an algorithm?
I Algorithmic analysis
I Considers the worst case (i.e. maximal) time required for
any input size n
I average case and best case complexity are also
sometimes used
I Focuses on the order of growth: for inputs of size n, does
the time required grow like log n? n2 ? 2n ?
I A related (harder) question is the complexity of the
problem itself:
What is the best we can hope for from any algorithm?
Orders of growth
Or also
for(int i = 0; i < n; i++)
for(int j = 0; j < i; j++)
a[i][j] = 1;
Examples
I i runs up to n, so it counts
I j runs up to n, so it counts
I k runs up to 3, independent of n, so doesn’t count
I l runs up to i which runs up to n, so it counts
I m runs up to k which is independent of n, so doesn’t count
I So this example takes O(n3 ) steps
Examples: logarithmic factors