Weighted Interval Scheduling
Consider requests 1,. . . ,n. For request i, s(i) is the start time and f(i) is the finish time, s(i) < f(i). Two requests i and j are compatible if they don’t overlap, i.e., f(i) ≤ s(j) or f(j) ≤ s(i). Each request i has a weight w(i). Goal: schedule the subset of compatible requests with maximum weight.
The nlogn dynamic programming solution
Sort requests in earliest finish time order.
f(1) ≤ f(2) ≤ · · · ≤ f(n)
Definition p(j) for interval j is the largest index i < j such that request i and j are compatible.
Array M[0 . . . n] holds the optimal solution’s values. M[k] is the maximum weight if requests from 1 to k are considered.
M[0] = 0
for j = 1 to n
M[j] = max(w[j] + M[p[j]], M[j-1])
Once we have M, the optimal solution can be derived by tracing it back in O(n) time. Sorting requests in earliest finish time take O(n log n) time. And the whole algorithm takes O(n log n) time.
Strassen
Matrix Multiplication
Take matrices A, B, multiply row i of A by column j of B to fill in entry i,j of resulting matrix, C. Running time is Θ(n3) on square matrices, where n is the dimension of each matrix.
The Strassen Algorithm
Master Theorem
T(n) = aT(n/b) + f(n)
- f(n) polynomially less than
- f(n) is Θ(nlogb(a) logk (n)), where k ≥ 0: T(n) = Θ(f(n)log(n)) = Θ(nlogb(a) logk+1(n))
- nlogb(a) polynomially less than f(n), and af(n/b) ≤ cf(n) for some constant c < 1 and all sufficiently large n: T(n) = Θ(f(n))
If nlogb(a) is greater, but not polynomially greater, than f(n), the Master Theorem cannot be used to determine a precise bound.