3.4.2 ANSWERS TO EXERCISES 555 (Ftp web hosting) 11. Arguing as
Friday, March 28th, 20083.4.2 ANSWERS TO EXERCISES 555 11. Arguing as in Section 1.2.10, which considers the special case n = 1, we see that the generating function is >( The mean is n + znctcN (n/t) = n(1 + H,v -Hn); and the variance turns out to be n(HN -If,) -n2(H~)-Ha)). 12. (Note that ~-l = (btt). . (bs3)(&2), so we seek an algorithm that goes from the representation of VT to that for r-l.) Set b, + j for 1 5 j 2 t. Then for j = 2, 3, t (in this order) interchange b, c) ba3. Finally for j = t, , 3, 2 (in this order) sei baJ + b,. (The algorithm is based on the fact that (att)nl = nl(btt).) 13. Renumbering the deck 0, 1, . , 2n -2, we find that s takes card number z into card number (22) mod (2n -I), while c takes card z into (zz f 1) mod (2n -1). We have (c followed by s) = cs = sc2. Therefore any product of c s and s s can be transformed into the form sZck. Also 2 p(2n-1) = 1 (modulo (2n -1)); since .s~( ~- ) and c2n-1 are the identity permutation, at most (2n -l)p(2n -1) arrangements are possible. (The exact number of different arrangements is (2n -1)/c, where k is the order of 2 modulo (2n -1). For if sk = c3, then c3 fixes the card 0, so sk = c3 = identity.) For further details, see SIAM Review 3 (1961), 293-297. 14. Set Y, +-j for t -n < j 2 t. Then for j = t, t -1, . . , t -n f 1 do the following operations: Set k + Lju] + 1. If k > t -n then set X, + Yk and Yk + Y,; otherwise if Ic = X, for some i > j (a symbol table algorithm could be used), then set X, + Y, and Yi + Y3; otherwise set X, + k. (The idea is to let Ytpn+l, , Yj represent Xt–n+l, . . . , X,, and if i > j and X, 2 t -n also to let Y, represent Xx,, in the execution of Algorithm P.) 15. We may assume that n 5 iN, otherwise it suffices to find the N-n elements not in the sample. Using a hash table of size 2n, the idea is to generate random numbers between 1 and N, storing them in the table and discarding duplicates, until n distinct numbers have been generated. The average number of random numbers generated is N/N+N/(N-l)+…+N/(N-n+l) < 2n, by exercise 3.3.2-10, and the average time to process each number is O(1). We want to output the results in increasing order, and this can be done as follows: Using an ordered hash table (exercise 6.4-66) with linear probing, the hash table will appear as if the values had been inserted in increasing order. Thus if we use a monotonic hash address such as [nlc/iV] for the key k, it will be a simple matter to output the keys in sorted order by making at most two passes over the table. 16. In most cases it will be best simply to select n records one at a time by Walker s alias method, with probabilities proportional to their weights, rejecting an element that occurs more than once. But if some weights are significantly larger than others, the following algorithm will sometimes be better [cf. Wong and Easton, SIAM J. Cornput. 9 (1980), ill-1131. Begin with a complete binary tree of weights x2, where x2 = ~2~ + zzi+l for 1 5 i < N and z,Afz-l = w, for 1 5 i 2 N; then do the following operation n times: Set j + 1, and generate X = Uxl. If X < XZ~, set j +--2j, otherwise set X + X -2~~ and j + 2j f 1; repeat this until j > N. Then select elementj-N+l, seti + [j/2], and while i 2 1 set x2 +- zz -x3 and i +-[i/ZJ. Finally set q + 0.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.