This recitation began with everyone introducing themselves. I was mildly surprised about the mix of people, year- and major-wise.
Most of my notes are in the form of iPad annotations on a PDF, but I'll note some retrospective thoughts here too.
Algorithms
Correctness
We did a proof by contradiction, whereas the notes used induction
Efficiency
Resources used by a program, e.g. storage space or running time
Asymptotic Notation
As opposed to absolute (downsides: depends on machine, hard to describe speed on all inputs)
Big O
g(n)∈O(f(n))⟺n→∞limf(n)g(n)<∞
or iff there exists a positive real number c and positive integer n0 such that g(n)≤c⋅f(n) for all n≥n0. g doesn't outpace f, g is upper-bounded by f
Big Ω
g(n)∈Ω(f(n))⟺n→∞limg(n)f(n)<∞
or iff there exists a positive real number c and positive integer n0 such that c⋅f(n)≥g(n) for all n≥n0. g is lower-bounded by f
Big Θ
g(n)∈Θ(f(n))⟺g(n)∈O(f(n))∩Ω(f(n))
The problems we'll look at fall into these:
- Constant: Θ(1)
- Logarithmic: Θ(logn)
- Linear (graphs often ∣V∣+∣E∣): Θ(n)
- Quadratic (matrices): Θ(n2)
- Polynomial: Θ(nc)
- Exponential: 2Θ(nc)
Model of Computation
- We'll use a w-bit Word-RAM model of computation
- Computer as random acess array of machine words (sequence of w bits representing an integer from {0,...,2w−1}) called memory
- Processor an perform operations on the memory
- Constant time: add, subtract, multiply, integer division, modulo, bitwise operations, binary comparisons; read/write at address a
Data Structure
- Way to support non-constant amount of data, supporting a set of operations to interact with that data
-
Interface: set of operations supported by a data structure
- Many data structures might support the same interface, but with different performance
- Many problems can be solved more easily by choosing the right data structure
-
Static array: most primitive data structure native to the Word-RAM; contiguous sequence of words reserved in memory, supporting a static sequence interface
StaticArray(n)
: allocate static array of size n initialized to 0 in Θ(n) time
StaticArray.get_at(i)
: Θ(1)
StaticArray.set_at(i, x)
: Θ(1)
Running Time Analysis
- I appreciate the Python code showing an implementation of a static array!
- We did this the same way edX 6.0001 introduced, I'm wondering how people do it once they're more practiced / how to efficiently get the hang of this more
Asymptotics Exercises
- When I saw that we had to find a tight, simple asymptotic bound for (6006n), I immediately thought we'd have to use Stirling's approximation, but it turns out that we could cancel terms
- The last problem — show (6n)!∈/Θ(n!) but log((6n)!)∈Θ(log(n!)) — does actually use Stirling's approximation:
log2n!=nlog2n−nlog2e+O(log2n)
Videos
Algorithms Lesson 6: Big O, Big Omega, and Big Theta Notation
- So Big O: upper-bound, Big Ω: lower-bound, Big Θ: intersection
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7)
- Find the fastest growing term