

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Due: Monday, after the break, in class or before 2 pm on the following Tuesday (drop- off box will be in front of IST 337 when the deparment is closed).
Solve exercises from the textbook:
On page 229, 1 (heap construction the maximum at the root)
Answer.
5 3 7 4
8 6
1
5 3 6 4
8 7
1
5 3 6 4
1 7
8
1 3 6 4
5 7
8
1
8
1
1
8
1 6
8
5
1 6
8
1
5 6
8
1 3
5 6
8
1 3 7
5 6
8
1 3 6
5 7
8
1 3 6 4
5 7
8
a.
b.
c. No, we can try another sequence, 2, 3, 4, 6, 5, 1, 0.
On page 229, 2 (heap checking) Answer. for (i = 2; i <= n; i++) if (H[i] > H[i/2]) return 0; return 1;
The running time is O ( n ).
On page 246, 10 (post office location, use problem of computing median),
Answer. The first observation is that under some circumstances we can easily improve the location of the post-office. If the post office is at ( x , y ) and there are a > n /2 input
points with xi < x , we can change x into x − ε , and in the summation
n i = 1
have a terms decreased by ε and at most n − a < a terms increased by ε , thus the summa- tion will decrease.
When such easy (if small) improvement is not possible? When the number of xi ’s smaller than x is at most n /2, and the number of xi ’s larger than x is at most n /2. Thus x is the median of xi ’s.
Similarly, y has to be a median of yi ’s. In other words, we reduced the problem of best location for the post-office to the median problem (and we can solve it in time O ( n )).
On page 276, 3.
Answer. Order m of the B-tree is the maximum branching of a node (number of chil- dren), and m /2 is the minimum branching of a non-root. The minimum non-root subtree with one level has at least m /2 keys, the minimum non-root subtree with two levels has at least ( m /2)^2 keys, and in general, the minimum non-root tree with L levels has at least ( m /2) L^ keys. The minimum tree with L levels has two subtrees, each with L − 1 levels and thus altogether at least 2×( m /2) L −^1 keys.
To guarantee at most L levels we should have at most 2×( m /2) L^ keys. We want to guarantee at most 4 levels (3 on the disk), thus 2×( m /2)^4 ≥ 108 m ≥ 10 2× 2 0.75^ ≈ 168.