Design and Analysis of Algorithms (Divide & Conquer: Smarter Interval Scheduling, Master Therorem)

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.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值