您的位置:首页 > 编程语言 > Go语言

Algorithm Study Notes

2012-05-16 16:35 183 查看
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

If f(n) = O(nlogb a - e) for some constant e > 0, then T(n) = Q(nlogb a).
If f(n) = Q(nlogb a - e), then T(n) = Q(nlogb a lgn).
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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: