Algorithm Study Notes

0.Master Method 时时勤拂拭

Master Theorem 

Let a ³ 1 and b 1 be constants, let f(n) be a function, and let T(n) be defined as the nonnegative integers by the recurrence

T(n) = aT(n/b) + f(n),

where we interpret n/b to mean either ën/bû or én/bù. Then T(n) can be bounded asymptotically as follows

  1. If f(n) = O(nlogb a - e) for some constant e > 0, then T(n) = Q(nlogb a).
  2. If f(n) = Q(nlogb a - e), then T(n) = Q(nlogb a lgn).
  3. If f(n) = W(nlogb a + e) for some constant e > 0, and if af(n/b) £ cf(n) for some constant c 1 and all sufficiently large n,then T(n) = Q(f(n)).
Chapter 5. Random Algorithm

HIRE_ASSISTANT(n) {
1    best = 0; // candidate 0 is a least-qualified dummy candidate
2    for i = 1 to n {
3        interview candidate i;
4        if candidate i is better than candidate best {
5            best = i;
6            hire candidate i;
7        }
8    }
}

RANDOMIZED_HIRE_ASSISTANT(n) {
1    randomly permute the list of candidates
2    HIRE_ASSISTANT(n)
}

RANDOMIZE_IN_PLACE(A) {
1    n = A.length;
2    for i = 1 to n
3        swap(A[i], A[RANDOM(i, n)]);
}

Expected Cost for hire = O(c_h*ln(n))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值