You are on page 1of 217

Selected Homework Solutions Unit 1

CMPSC 465

Exercise 2.1-3
Here, we work with the linear search, specified as follows:
LINEAR-SEARCH(A, v)
Input: A = <a1, a, , an>; and a value v.
Output: index i if there exists an i in 1..n s.t. v = A[i]; NIL, otherwise.

We can write pseudocode as follows:


LINEAR-SEARCH(A, v)
i =1
while i A.length and A[i] v // check elements of array until end or we find key
{
i=i+1
}

if i == A.length + 1 // case that we searched to end of array, didnt find key


return NIL
else // case that we found key
return i

Here is a loop invariant for the loop above:


At the start of the ith iteration of the while loop, A[1..i-1] doesnt contain value v

Now we use the loop invariant to do a proof of correctness:


Initialization:
Before the first iteration of the loop, i = 1. The subarray A[1..i-1] is empty, so the loop invariant vacuously holds.

Maintenance:
For i Z s.t. 1 i A.length, consider iteration i. By the loop invariant, at the start of iteration i, A[1..i-1] doesnt
contain v. The loop body is only executed when A[i] is not v and we have not exceeded A.length. So, when the ith
iteration ends, A[1..i] will not contain value v. Put differently, at the start of the (i+1)st iteration, A[1..i-1] will once again
not contain value v.

Termination:
There are two possible ways the loop terminates:
If there exists an index i such that A[i] == v, then the while loop will terminate at the end of the ith iteration.
The loop invariant says A[1..i-1] doesnt contain v, which is true. And, in this case, i will not reach A.length + 1,
so the algorithm returns i s.t. A[i] = v, which is correct.
Otherwise, the loop terminates when i = n + 1 (where n = A.length), which implies n = i - 1. By the loop
invariant, A[1..i-1] is the entire array A[1..n], and it doesnt contain value v, so NIL will correctly be returned by
the algorithm.

Note: Remember a few things from intro programming and from Epp:
Remember to think about which kind of loop to use for a problem. We dont know how many iterations the linear search loop will run until its
done, so we should use an indeterminate loop structure. (If we do, the proof is cleaner.)
As noted in Epp, the only way to get out of a loop should be by having the loop test fail (or, in the for case, the counter reach the end). Dont
return or break out of a loop; proving the maintenance step becomes very tricky if you do.

Page 1 of 4 PSU CMPSC 465 Spring 2013


Exercise 2.3-1
The figure below illustrates the operations of the procedure bottom-up of the merge sort on the array
A = {3, 41, 52, 26, 38, 57, 9, 49}:

3 9 26 38 41 49 52 57

3 26 41 52 9 38 49 57

3 41 26 52 38 57 9 49

3 41 52 26 38 57 9 49

The algorithm consists of merging pairs of 1-item sequence to form sorted sequences of length 2, merging pairs of sequences
of length 2 to form sorted sequences of length 4, and so on, until two sequences of length n/2 are merged to form the final
sorted sequence of length n.

Exercise 4.4-1
The recurrence is T(n) = 3T( ) + n. We use a recurrence tree to determine the asymptotic upper bound on this recurrence.

Because we know that floors and ceilings usually do not matter when solving recurrences, we create a recurrence tree for the
recurrence T(n) = 3T(n/2) + n. For convenience, we assume that n is an exact power of 2 so that all subproblem sizes are
integers.

n n

n/2 n/2 n/2 3/2n

lgn
n/4 n/4 n/4 n/4 n/4 n/4 n/4 n/4 n/4 (3/2)2n

.
.
.
. . .
T(1) T(1) T(1) T(1) T(1) T(1)

Total: O( )
Because subproblem sizes decrease by a factor of 2 each time when go down one level, we eventually must reach a boundary
condition T(1). To determine the depth of the tree, we find that the subproblem size for a node at depth i is n/2i. Thus, the
subproblem size hits n = 1 when n/2i = 1 or, equivalently, when i = lgn. Thus, the tree has lgn + 1 levels (at depth 0, 1, 2, 3,
, lgn).

Next we determine the cost at each level of the tree. Each level has 3 times more nodes than the level above, and so the
number of nodes at depth i is 3i. Because subproblem sizes reduce by a factor of 2 for each level when go down from the
root, each node at depth i, for i = 0, 1, 2, 3, , lgn 1, has a cost of n/2i. Multiplying, we see that the total cost over all
nodes at depth i, for i = 0, 1, 2, 3, , lgn 1, is 3i * n/2i = (3/2)in. The bottom level, at depth lgn, has = nodes, each
contributing cost T(1), for a total cost of T(1), which is ( ), since we assume that T(1) is a constant.

Page 2 of 4 PSU CMPSC 465 Spring 2013


Now we add up the costs over all levels to determine the cost for the entire tree:
T(n) = n + + + + + +

= + by using Sigma to sum all the elements except the last one

= + by geometric series sum formula


=2 2n + by evaluating the fraction
=O

Thus, we have derived a guess of T(n) = O for our original recurrence T(n) = 3T( ) + n. Now we can use the
inductive proof to verify that our guess is correct.

To prove:
For all integers n s.t. n 1, the property P(n):
The closed form T(n) , for some constants d and c s.t. d > 0 and c > 0,
matches the recurrence T(n) = 3T( ) + n.

Proof:
We will reason with strong induction.

Since were only proving a bound and not an exact running time, we dont need to worry about a base case.

Inductive Step:
Let k Z s.t. k 1 and assume i Z s.t. 1 i k, P(i) is true. i.e. T(i) matches the recurrence.
[inductive hypothesis]

Consider T(k+1):
T(k + 1) = 3T( )+k+1 by using the recurrence definition (as k 1 implies
k + 1 2, so we are in the recursive case)
3d (k +1) + k + 1 by subs. from inductive hypothesis,
(k + 1)/2, and d c + 1
(k +1) + k + 1 by laws of exp.
(k +1) + k + 1 by laws of exp. and log.
(k +1) as long as c 2, (k +1) (k + 1) (k +1)

So P(k + 1) is true.

So, by the principle of strong mathematical induction, P(n) is true for all integers n s.t. n 1, and constant d = 3, c = 2.

Page 3 of 4 PSU CMPSC 465 Spring 2013


Exercise 4.5-1
a) Use the master method to give tight asymptotic bounds for the recurrence T(n) = 2T(n/4) + 1.

Solution:
For this recurrence, we have a = 2, b = 4, f (n) = 1, and thus we have that = . Since f (n) = 1 = O( ),
where = 0.2, we can apply case 1 of the master theorem and conclude that the solution is T(n) = ( ) = ( ) =
( ).

b) Use the master method to give tight asymptotic bounds for the recurrence T(n) = 2T(n/4) + .

Solution:
For this recurrence, we have a = 2, b = 4, f (n) = , and thus we have that = = = . Since f (n) = ( ),
we can apply case 2 of the master theorem and conclude that the solution is T(n) = ( ).

c) Use the master method to give tight asymptotic bounds for the recurrence T(n) = 2T(n/4) + n.

Solution:
For this recurrence, we have a = 2, b = 4, f (n) = n, and thus we have that = . Since f (n) = ( ) , where
, we can apply case 3 of the master theorem if we can show that the regularity condition holds for f (n).

To show the regularity condition, we need to prove that af (n/b) cf (n) for some constant c < 1 and all sufficiently large
n. If we can prove this, we can conclude that T(n) = (f (n)) by case 3 of the master theorem.

Proof of the regularity condition:


af (n/b) = 2(n/4) = n/2 cf (n) for c = 0.7, and n 2.

So, we can conclude that the solution is T(n) = (f (n)) = (n).

d) Use the master method to give tight asymptotic bounds for the recurrence T(n) = 2T(n/4) + n2.

Solution:
For this recurrence, we have a = 2, b = 4, f (n) = n2, and thus we have that = . Since f (n) =( ) , where
, we can apply case 3 of the master theorem if we can show that the regularity condition holds for f (n).

Proof of the regularity condition:


af (n/b) = 2 = (1/8) n2 c f (n) for c = 0.5, and n 4.

So, we can conclude that the solution is T(n) = (n2).

Page 4 of 4 PSU CMPSC 465 Spring 2013


Selected Homework Solutions Unit 2
CMPSC 465

Exercise 6.1-1
Problem: What are the minimum and maximum numbers of elements in a heap of height h?

Since a heap is an almost-complete binary tree (complete at all levels except possibly the lowest), it has at most
1+2+22+23++2h=2h+1-1 elements (if it is complete) and at least 2h-1+1=2h elements (if the lowest level has just 1 element
and the other levels are complete).

Exercise 6.1-3
Problem: Show that in any subtree of a max-heap, the root of the subtree contains the largest value occurring anywhere in
that subtree.

To prove:
For any subtree rooted at node k of a max-heap A[1, 2, ... , n], the property P(k):
The node k of the subtree rooted at k contains the largest value occurring anywhere in that subtree.

Proof:
Base Case:
When k n / 2 + 1, n , k is a leaf node of a max-heap since n / 2 is the index of the last parent, and the

subtree rooted at k just contains one node. Thus, node k contains the largest value in that subtree.

Inductive Step:
Let k s.t. k is an internal node of a max-heap, and assume s.t. k < i n, P(i) is true. i.e.
The node i of the subtree rooted at i contains the largest value occurring anywhere in that subtree.
[inductive hypothesis]

Now let us consider node k:


1. k's left child 2k and right child 2k + 1 contain the largest value of k's left and right subtree, respectively.
(by the inductive hypothesis that for k < i n, P(i) is true)
2. k's value is larger than its left child 2k and right child 2k + 1.
(by the max-heap property)

So, we can conclude that node k contains the largest value in the subtree rooted at k.

Thus, by the principle of strong mathematical induction, P(k) is true for all nodes in a max-heap.

Exercise 6.1-4
Problem: Where in a max-heap might the smallest element reside, assuming that all elements are distinct?

The smallest element can only be one of leaf nodes. If not, it will have its own subtree and is larger than any element on that
subtree, which contradicts the fact that it is the smallest element.

Page 1 of 6 PSU CMPSC 465 Spring 2013


Exercise 6.1-6
Problem: Is the array with values (23, 17, 14, 6, 13, 10, 1, 5, 7, 12) a max-heap?

Consider this illustration of the heap:

1
23
2 3
17 14
4 5 6 7
6 13 10 1
8 9 10
5 7 12

So, this array isn't a max-heap. As shown in the figure above, the value of node 9 is greater than that of its parent node 4.

Exercise 6.4-2
We argue the correctness of HEAPSORT using the following loop invariant:

At the start of each iteration of the for loop of lines 2-5, the subarray A[1..i] is a max-heap containing the i smallest
elements of A[1..n], and the subarray A[i+1..n] contains the n-i lagest elements of A[1..n], sorted.

Proof:
We need to show that this invariant is true prior to the first step, that each iteration of the loop maintains the invariant. It
provides the property to show correctness of HEAPSORT.

Initialization:
Prior to the first iteration of the loop, i = n. The subarray A[1..i] is a max-heap due to BUILD-MAX-HEAP. The subarray
A[i + 1..n] is empty, hence the claim about it being sorted is vacuously true.

Maintenance:
For each iteration, By the loop invariant, A[1..i] is a max-heap containing the i smallest elements of A[1..n], so the A[1]
contains the (ni+1)st largest element. The execution of line 3 exchanges A[1] with A[i], so it makes the subarray A[i..n]
contain the (ni+1) largest elements of A[1..n], sorted. The heap size of A is decreased in to heap-size(A) = i 1. Now
the subarray A[1..i1] is not a max-heap, since the root node violates the map-heap property. But the children of the root
maintain the max-heap property, so we can restore the max-heap property by calling MAX-HEAPIFY(A, 1), which leaves a
max-heap in A[1..i1]. Consequently, the loop invariant is reestablished for the next iteration.

Termination:
At termination, i = 1. By the loop invariant, the subarray A[2.. n] contains the n 1 largest elements of A[1..n], sorted, and
thus, A[1] contains the smallest element of A[1..n]. A[1..n] is a sorted array.

Page 2 of 6 PSU CMPSC 465 Spring 2013


Exercise 6.4-3

Problem: What is the running time of HEAPSORT on an array A of length n that is already sorted in increasing order? What
about decreasing order?

The running time of HEAPSORT on an array of length that is already sorted in increasing order is (n lgn), because even
though it is already sorted, it will be transformed back into a heap and sorted.

The running time of HEAPSORT on an array of length that is sorted in decreasing order will be (n lgn). This occurs because
even though the heap will be built in linear time, every time the element is removed and HEAPIFY is called, it could cover the
full height of the tree.

Exercise 6.5-1
Problem: Illustrate the operation of HEAP-EXTRACT-MAX on the heap A = <15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1>.

Page 3 of 6 PSU CMPSC 465 Spring 2013


Exercise 6.5-2
Problem: Illustrate the operation of MAX-HEAP-INSERT (A, 10) on the heap A = (15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1).

Exercise 7.1-3
Problem: Give a brief argument that the running time of PARTITION on a subarray of size n is (n).

Since each iteration of the for loop involves a constant number of operations and there are n iterations total, the running time
is (n).

Page 4 of 6 PSU CMPSC 465 Spring 2013


Exercise 7.2-1
Use the substitution method to prove that the recurrence T(n) = T(n-1) + (n) has the solution T(n) = (n2), as claimed at the
beginning of Section 7.2.

To prove:
For all integers n s.t. n 1, the property P(n):
The closed form T(n) and T(n) , for some constants c and d, s.t. c > 0 and d > 0, matches the recurrence
T(n) = T(n1) + (n).

Proof:
We will reason with strong induction.

Base case:
Let n = 1. T(1) = T(0) + (1) = (1) , if c is large enough. T(1) = T(0) + (1) = (1) , if d is small
enough. So P(1) holds.

Inductive Step:
Let k Z s.t. k 1 and assume i Z s.t. 1 i k1, P(i) is true. i.e.
T(i) and T(i) matches the recurrence. [inductive hypothesis]

Consider T(k) to find an upper bound:


T(k ) = T(k1) + (k). by using the recurrence definition
c(k1)2 + c1k by subs. from inductive hypothesis, where c1 is some constant
= c(k2 2k + 1) + c1k since (k1)2 = k2 2k + 1
= ck2 (2cc1)k + c by combining like terms
ck2 as long as c > c1

Consider T(k) to find a lower bound:


T(k ) = T(k1) + (k). by using the recurrence definition
d(k1)2 + c1k by subs. from inductive hypothesis, where c1 is some constant
= d(k2 2k + 1) + c1k since (k1)2 = k2 2k + 1
= dk2 + (c12d)k + d by combining like terms
dk2 as long as c12d 0 or 0 < d c1/2

So P(k) is true.

So, by the principle of strong mathematical induction, P(n) is true for all integers n s.t. n 1, and constants c > c1, 0 < d
c1/2.

Since T(n) = (n2) and T(n) = O(n2), we obtain that T(n) = (n2).

Page 5 of 6 PSU CMPSC 465 Spring 2013


Exercise 7.2-4
Problem: Banks often record transactions on an account in order of the times of the transaction, but many people like to
receive their bank statements with checks listed in order by check number. People usually write checks in order by check
number, and merchants usually cash them with reasonable dispatch. The problem of converting time-of-transaction ordering
is therefore the problem of sorting almost-sorted input. Argue that the procedure INSERTION-SORT would tend to beat the
procedure QUICKSORT on this problem.

INSERTION-SORTs running time on perfectly-sorted input runs in (n) time. So, it takes almost (n) running time to sort an
almost-sorted input with INSERTION-SORT. However, QUICKSORT requires almost (n2) running time, recalling that it takes
(n2) time to sort perfectly-sorted input. This is because when we pick the last element as the pivot, it is usually the biggest
one, and it will produce one subproblem with close to n 1 elements and one with 0 elements. Since the cost of PARTITION
procedure of QUICKSORT is (n), the recurrence running time of QUICKSORT is T(n) = T(n 1) +(n). In another problem,
we, use the substitution method to prove that the recurrence T(n) = T(n 1) +(n) has the solution T(n) = (n2). So we
use INSERTION-SORT rather than QUICKSORT in this situation when the input is almost sorted.

Exercise 8.4-2
Problem: Explain why the worst-case running time for bucket sort is (n2). What simple change to the algorithm preserve its
linear average-case running time and makes its worst-case running time O(n lgn)?

The worst case for bucket sort occurs when the all inputs fall into a single bucket, for example. Since we use INSERTION-
SORT for sorting buckets and INSERTION-SORT has a worst case of (n2), the worst case run time for bucket sort is (n2).

By using an algorithm like MERGE-SORT with worst case run time time of O(n lgn) instead of INSERTION-SORT for sorting
buckets, we can ensure that the worst case of bucket sort is O(n lgn) without affecting the average case running time.

Exercise 8.4-3
Problem: Let X be a random variable that is equal to the number of heads in two flips of a fair coin. What is E[X2]? What is
E2[X]?

E[X2] = 12 * P(head in one flip) + 02 * P(tail in one flip)


= 1 * 1/2 + 0 * 1/2
= 1/2

E2[X] = E[X] * E[X] as the two flips are independent


= 1/2 * 1/2 as E[X] = 1/2
= 1/4

Page 6 of 6 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 3, Chapter 11
CMPSC 465 Spring 2013

Exercise 11.1-1

Suppose that a dynamic set S is represented by a direct-address table T of length m. Describe a procedure that finds the
maximum element of S. What is the worst-case performance of your procedure?

Solution:

We can do a linear search to find the maximum element in S as follows:

Pre-condition: table T is not empty; m Z+, m 1.


Post-condition: FCTVAL == maximum value of dynamic set stored in T.

FindMax (T, m)
{
max =

for i = 1 to m
{
if T[i] != NIL && max < T[i]
max = T[i]
}
return max
}

In the worst-case searching the entire table is needed. Thus the procedure must take O (m) time.

Page 1 of 7 PSU CMPSC 465 Spring 2013


Exercise 11.2-1

Suppose we use a hash function h to hash n distinct keys into an array T of length m. Assuming simple uniform hashing,
what is the expected number of collisions? More precisely, what is the expected cardinality of {{k, l}: k l and h (k) = h (l)}?

Solution:

For each pair of keys k, l, where k l, define the indicator random variable Xlk = I {h (k) = h (l)}. Since we assume simple
uniform hashing, Pr { Xlk = 1} = Pr { h (k) = h (l)} = 1 / m, and so E[Xlk] = 1 / m.

Now define the random variable Y to be the total number of collisions, so that . The expected number of collisions

is
E[Y ] = E[ X kl ] since Y = X kl
kl kl

= E[ X kl ] by linearity of expectation
kl

1 1
= since E[ X kl ] =
kl m m
n 1
= by choosing k and l out of n keys
2 m
n(n 1) 1 n n! n n! n(n 1)
= by = r!(n r)! , = 2!(n 2)! =
2 m r 2 2
n(n 1)
=
2m

Exercise 11.2-2
Demonstrate what happens when we insert the keys 5, 28, 19, 15, 20, 33, 12, 17, 10 into a hash table with collisions resolved
by chaining. Let the table have 9 slots, and let the hash function be h (k) = k mod 9.

Solution: omitted.

Page 2 of 7 PSU CMPSC 465 Spring 2013


Exercise 11.2-3
Professor Marley hypothesizes that he can obtain substantial performance gains by modifying the chaining scheme to keep
each list in sorted order. How does the professors modification affect the running time for successful searches, unsuccessful
searches, insertions, and deletions?

Solution:

Successful searches: (1 + ), which is identical to the original running time. The element we search for is equally likely
to be any of the elements in the hash table, and the proof of the running time for successful searches is similar to what
we did in the lecture.
Unsuccessful searches: 1/2 of the original running time, but still (1 + ), if we simply assume that the probability that
one element's value falls between two consecutive elements in the hash slot is uniformly distributed. This is because the
value of the element we search for is equally likely to fall between any consecutive elements in the hash slot, and once
we find a larger value, we can stop searching. Thus, the running time for unsuccessful searches is a half of the original
running time. Its proof is similar to what we did in the lecture.
Insertions: (1 + ), compared to the original running time of (1). This is because we need to find the right location
instead of the head to insert the element so that the list remains sorted. The operation of insertions is similar to the
operation of unsuccessful searches in this case.
Deletions: (1 + ), same as successful searches.

Page 3 of 7 PSU CMPSC 465 Spring 2013


Exercise 11.3-3
Consider a version of the division method in which h(k) = k mod m, where m = 2p 1 and k is a character string interpreted in
radix 2p. Show that if we can derive string x from string y by permuting its characters, then x and y hash to the same value.
Give an example of an application in which this property would be undesirable in a hash function.

Solution:
First, we observe that we can generate any permutation by a sequence of interchanges of pairs of characters. One can prove
this property formally, but informally, consider that both heapsort and quicksort work by interchanging pairs of elements and
that they have to be able to produce any permutation of their input array. Thus, it suffices to show that if string x can be
derived from string y by interchanging a single pair of characters, then x and y hash to the same value.

Let xi be the ith character in x, and similarly for yi. We can interpret x in radix 2p as , and interpret y as . So

h(x) = ( ) mod (2p 1). Similarly, h(y) = ( ) mod (2p 1).

Suppose that x and y are identical strings of n characters except that the characters in positions a and b are interchanged:
xa = yb and ya = xb. (1)
Without loss of generality, let a > b. We have:

h(x) h(y) = ( ) mod (2p 1) ( ) mod (2p 1) (2)

Since 0 h(x), h(y) < 2p 1, we have that (2p 1) < h(x) h(y) < 2p 1. If we show that (h(x) h(y)) mod (2p 1) = 0, then
h(x) = h(y). To prove (h(x) h(y)) mod (2p 1) = 0, we have:

(h(x) h(y)) mod (2p 1) = (( ) mod (2p 1) ( ) mod (2p 1))

mod (2p 1) by (2)

=( ) mod (2p 1) by relation in footnote1

= ((xa2ap + xb2bp) (ya2ap + yb2bp)) mod (2p 1) as x and y are identical strings
of n characters except that
chars. in positions a and
b are interchanged
= ((xa2ap + xb2bp) (xb2ap + xa2bp)) mod (2p 1) as xa = yb, xb = ya see (1)
= ((xa xb)2ap + (xb xa)2bp) mod (2p 1) by combining like terms
= ((xa xb)2ap (xa xb)2bp) mod (2p 1) as (xb xa) = (xa xb)
= ((xa xb)(2ap 2bp)) mod (2p 1) by factoring out (xa xb)
= ((xa xb)(2ap(2bp/2bp) 2bp)) mod (2p 1) by multiplication by
2bp/2bp = 1
= ((xa xb)2bp(2(a b)p 1)) mod (2p 1) by factoring out 2bp

= ((xa xb)2bp( )(2p 1)) mod (2p 1) by substituting [2(a b)p 1]2

=0 since one factor is 2p 1


1 Consider the congruence relation: (m o m ) mod n = ((m mod n) o (m mod n)) mod n, where o is +, , or *
1 2 1 2

2 Consider the equation = (geometric series) and multiplying both sides by 2p 1 to get

2(a b)p 1 = ( )(2p 1)]

Page 4 of 7 PSU CMPSC 465 Spring 2013


Because we deduced earlier that (h(x) h(y)) mod (2p 1) = ((xa xb)2bp(2(a b)p 1)) mod (2p 1) and have shown here that
((xa xb)2bp(2(a b)p 1)) mod (2p 1) = 0, we can conclude (h(x) h(y)) mod (2p 1) = 0, and thus h(x) = h(y). So we have
proven that if we can derive string x from string y by permuting its characters, then x and y hash to the same value.

Examples of applications:
A dictionary which contains words expressed by ASCII code can be one of such example when each character of the
dictionary is interpreted in radix 28 = 256 and m = 255. The dictionary, for instance, might have words "STOP," "TOPS,"
"SPOT," "POTS," all of which are hashed into the same slot.

Exercise 11.3-4

Consider a hash table of size m = 1000 and a corresponding hash function for . Compute
the locations to which the keys 61, 62, 63, 64, and 65 are mapped.

Solution:

Page 5 of 7 PSU CMPSC 465 Spring 2013


Exercise 11.4-1
Consider inserting the keys 10, 22, 31, 4, 15, 28, 17, 88, 59 into a hash table of length m = 11 using open addressing with the
auxiliary hash function h(k) = k. Illustrate the result of inserting these keys using linear probing, using quadratic probing with
c1 = 1 and c2 = 3, and using double hashing with h(k) = k and h2(k) = 1 + (k mod (m 1)).

Solution:

Linear Probing
With linear probing, we use the hash function h(k, i) = (h'(k) + i) mod m = (k + i) mod m. Consider hashing each of the
following keys:

1) Hashing 10:
h(10, 0) = (10 + 0) mod 11= 10. Thus we have T[10] = 10.
2) Hashing 22:
h(22, 0) = (22 + 0) mod 11 = 0. Thus we have T[0] = 22.
3) Hashing 31:
h(31, 0) = (31 + 0) mod 11 = 9. Thus we have T[9] = 31.
4) Hashing 4:
h(4, 0) = (4 + 0) mod 11 = 4. Thus we have T[4] = 4.
5) Hashing 15:
h(15, 0) = (15 + 0) mod 11 = 4, collision!
h(15, 1) = (15 + 1) mod 11 = 5. Thus we have T[5] = 15.
6) Hashing 28:
h(28, 0) = (28 + 0) mod 11 = 6. Thus we have T[6] = 28.
7) Hashing 17:
h(17, 0) = (17 + 0) mod 11 = 6, collision!
h(17, 1) = (17 + 1) mod 11 = 7. Thus we have T[7] = 17.
8) Hashing 88:
h(88, 0) = (88 + 0) mod 11 = 0, collision!
h(88, 1) = (88 + 1) mod 11 = 1. Thus we have T[1] = 88.
9) Hashing 59:
h(59, 0) = (59 + 0) mod 11 = 4, collision!
h(59, 1) = (59 + 1) mod 11 = 5, collision!
h(59, 2) = (59 + 2) mod 11 = 6, collision!
h(59, 3) = (59 + 3) mod 11 = 7, collision!
h(59, 4) = (59 + 4) mod 11 = 8. Thus we have T[8] = 59.

The final hash table is shown as:


key 22 88 4 15 28 17 59 31 10
index 1 2 3 4 5 6 7 8 9 10 11

Quadratic Probing
With quadratic probing, and c1 = 1, c2 = 3, we use the hash function h(k, i) = (h'(k) + i + 3i2) mod m = (k + i + 3i2) mod m.
Consider hashing each of the following keys:

1) Hashing 10:
h(10, 0) = (10 + 0 + 0) mod 11 = 10. Thus we have T[10] = 10.
2) Hashing 22:
h(22, 0) = (22 + 0 + 0) mod 11 = 0. Thus we have T[0] = 22.
3) Hashing 31:
h(31, 0) = (31 + 0 + 0) mod 11 = 9. Thus we have T[9] = 31.
4) Hashing 4:
h(4, 0) = (4 + 0 + 0) mod 11 = 4. Thus we have T[4] = 4.
5) Hashing 15:
h(15, 0) = (15 + 0 + 0) mod 11 = 4, collision!
h(15, 1) = (15 + 1 + 3) mod 11 = 8. Thus we have T[8] = 15.
6) Hashing 28:
h(28, 0) = (28 + 0 + 0) mod 11 = 6. Thus we have T[6] = 28.
7) Hashing 17:
Page 6 of 7 PSU CMPSC 465 Spring 2013
h(17, 0) = (17 + 0 + 0) mod 11 = 6, collision!
h(17, 1) = (17 + 1 + 3) mod 11 = 10, collision!
h(17, 2) = (17 + 2 + 12) mod 11 = 9, collision!
h(17, 3) = (17 + 3 + 27) mod 11 = 3. Thus we have T[3] = 17.
8) Hashing 88:
h(88, 0) = (88 + 0 + 0) mod 11 = 0, collision!
h(88, 1) = (88 + 1 + 3) mod 11 = 4, collision!
h(88, 2) = (88 + 2 + 12) mod 11 = 3, collision!
h(88, 3) = (88 + 3 + 27) mod 11 = 8, collision!
h(88, 4) = (88 + 4 + 48) mod 11 = 8, collision!
h(88, 5) = (88 + 5 + 75) mod 11 = 3, collision!
h(88, 6) = (88 + 6 + 108) mod 11 = 4, collision!
h(88, 7) = (88 + 7 + 147) mod 11 = 0, collision!
h(88, 8) = (88 + 8 + 192) mod 11 = 2. Thus we have T[2] = 88.
9) Hashing 59:
h(59, 0) = (59 + 0 + 0) mod 11 = 4, collision!
h(59, 1) = (59 + 1 + 3) mod 11 = 8, collision!
h(59, 2) = (59 + 2 + 12) mod 11 = 7. Thus we have T[7] = 59.

The final hash table is shown as:


key 22 88 17 4 28 59 15 31 10
index 1 2 3 4 5 6 7 8 9 10 11

Doubling Hashing
With double hashing, we use the hash function:
h(k, i) = (h'(k) + ih2'(k)) mod m = (k + i(1 + (k mod (m 1)))) mod m.
Consider hashing each of the following keys:

1) Hashing 10:
h(10, 0) = (10 + 0) mod 11 = 10. Thus we have T[10] = 10.
2) Hashing 22:
h(22, 0) = (22 + 0) mod 11 = 0. Thus we have T[0] = 22.
3) Hashing 31:
h(31, 0) = (31 + 0) mod 11 = 9. Thus we have T[9] = 31.
4) Hashing 4:
h(4, 0) = (4 + 0) mod 11 = 4. Thus we have T[4] = 4.
5) Hashing 15:
h(15, 0) = (15 + 0) mod 11 = 4, collision!
h(15, 1) = (15 + 1 * h2'(15)) mod 11 = 10, collision!
h(15, 2) = (15 + 2 * h2'(15)) mod 11 = 5. Thus we have T[5] = 15.
6) Hashing 28:
h(28, 0) = (28 + 0) mod 11 = 6. Thus we have T[6] = 28.
7) Hashing 17:
h(17, 0) = (17 + 0) mod 11 = 6, collision!
h(17, 1) = (17 + 1 * h2'(17)) mod 11 = 3. Thus we have T[3] = 17.
8) Hashing 88:
h(88, 0) = (88 + 0) mod 11 = 0, collision!
h(88, 1) = (88 + 1 * h2'(88)) mod 11 = 9, collision!
h(88, 2) = (88 + 2 * h2'(88)) mod 11 = 7. Thus we have T[7] = 88.
9) Hashing 59:
h(59, 0) = (59 + 0) mod 11 = 4, collision!
h(59, 1) = (59 + 1 * h2'(59)) mod 11 = 3, collision!
h(59, 2) = (59 + 2 * h2'(59)) mod 11 = 2. Thus we have T[2] = 59.

The final hash table is shown as:


key 22 59 17 4 15 28 88 31 10
index 1 2 3 4 5 6 7 8 9 10 11

Page 7 of 7 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 3: Chapter 13
CMPSC 465

Disclaimer: This is a draft of solutions that has been prepared by the TAs and the instructor makes no guarantees that
solutions presented here contain the level of detail that would be expected on an exam. Any errors or explanations you find
unclear should be reported to either of the TAs for corrections first.

Exercise 13.1-1
In the style of Figure 13.1(a), draw the complete binary search tree of height 3 on the keys {1, 2, , 15}. Add the NIL leaves
and color the nodes in three different ways such that the black-heights of the resulting red-black trees are 2, 3, and 4.

Solution:

Page 1 of 7 PSU CMPSC 465 Spring 2013


Exercise 13.1-2
Draw the red-black tree that results after TREE-INSERT is called on the tree shown in the figure below with key 36. If the
inserted node is colored red, is the resulting tree a red-black tree? What if it is colored black?

Solution:

If the node with key 36 is inserted and colored red, the red-black tree becomes:

36

We can see that it violates following red-black tree property:


A red node in the red-black tree cannot have a red node as its child.

So the resulting tree is not a red-black tree.

If the node with key 36 is inserted and colored black, the red-black tree becomes:

36

We can see that it violates following red-black tree property:


For each node, all paths from the node to descendent leaves contain the same number of black nodes (e.g. consider node
with key 30).

So the resulting tree is not a red-black tree either.

Page 2 of 7 PSU CMPSC 465 Spring 2013


Exercise 13.1-5
Show that the longest simple path from a node x in a red-black tree to a descendant leaf has length at most twice that of the
shortest simple path from node x to a descendant leaf.

Proof:

In the longest path, at least every other node is black. In the shortest path, at most every node is black. Since the two paths
contain equal numbers of black nodes, the length of the longest path is at most twice the length of the shortest path.

We can say this more precisely, as follows:


Since every path contains bh(x) black nodes, even the shortest path from x to a descendant leaf has length at least bh(x).
By definition, the longest path from x to a descendant leaf has length height(x). Since the longest path has bh(x) black
nodes and at least half the nodes on the longest path are black (by property 4 in CLRS), bh(x) height(x)/2, so

length of longest path = height(x) 2bh(x) twice length of shortest path.

Exercise 13.2-1

Write pseudocode for RIGHT-ROTATE.

Solution:

The pseudocode for RIGHT-ROTATE is shown below:

RIGHT-ROTATE (T, x)
y = x.left //set y
x.left = y.right // turn ys right subtree into xs left subtree
if y.right NIL
y.right.p = x
y.p = x:p // link xs parent to y
if x.p == NIL
T.root = y
else if x == x.p.right
x.p.right = y
else
x.p.left = y
y.right = x //put x on ys right
x.p = y

Page 3 of 7 PSU CMPSC 465 Spring 2013


Exercise 13.2-4
Show that any arbitrary n-node binary search tree can be transformed into any other arbitrary n-node binary search tree using
O (n) rotations. (Hint: First show that at most n1 right rotations suffice to transform the tree into a right-going chain.)

Solution:

Since the exercise asks about binary search trees rather than the more specific red-black trees, we assume here that leaves are
full-fledged nodes, and we ignore the sentinels.

Taking the books hint, we start by showing that with at most n1 right rotations, we can convert any binary search tree into
one that is just a right-going chain.

The idea is: Let us define the right spine as the root and all descendants of the root that are reachable by following only right
pointers from the root. A binary search tree that is just a right-going chain has all n nodes in the right spine.

As long as the tree is not just a right spine, repeatedly find some node y on the right spine that has a non-leaf left child x and
then perform a right rotation on y:

(In the above figure, note that any of , , and can be an empty subtree.)

Observe that this right rotation adds x to the right spine, and no other nodes leave the right spine. Thus, this right rotation
increases the number of nodes in the right spine by 1. Any binary search tree starts out with at least one node the root
in the right spine. Moreover, if there are any nodes not on the right spine, then at least one such node has a parent on the right
spine. Thus, at most n1 right rotations are needed to put all nodes in the right spine, so that the tree consists of a single right-
going chain.

If we knew the sequence of right rotations that transforms an arbitrary binary search tree T to a single right-going chain T,
then we could perform this sequence in reverse turning each right rotation into its inverse left rotation to transform T
back into T.

Therefore, here is how we can transform any binary search tree T1 into any other binary search tree T2. Let T be the unique
right-going chain consisting of the nodes of T1 (which is the same as the nodes of T2). Let r = <r1, r2, ..., rk> be a sequence of
right rotations that transforms T1 to T, and let r = <r1, r2, ..., rk> be a sequence of right rotations that transforms T2 to T.
We know that there exist sequences r and r with k, k n1. For each right rotation ri, let li be the corresponding inverse
left rotation. Then the sequence <r1, r2, ..., rk, lk, lk-1, , l2, l1> transforms T1 to T2 in at most 2n2 rotations.

Page 4 of 7 PSU CMPSC 465 Spring 2013


Exercise 13.3-2
Show the red-black trees that result after successively inserting the keys 41, 38, 31, 12, 19, 8 into an initially empty red-black
tree.

Solution:

Insert 41 Insert 38 Insert 31

Insert 12

Insert 19

Insert 8

Page 5 of 7 PSU CMPSC 465 Spring 2013


Exercise 13.3-3
Suppose that the black-height of each of the subtrees , , , , in Figures 13.5 and 13.6 is k. Label each node in each figure
with its black-height to verify that the indicated transformation preserves property 5.

Figure 13.5

Figure 13.6

Solution:

In Figure 13.5, nodes A, B, and D have black-height k + 1 in all cases, because each of their subtrees has black-height k and a
black root. Node C has black-height k + 1 on the left (because its red children have black-height k + 1) and black-height k + 2
on the right (because its black children have black-height k + 1).

In Figure 13.6, nodes A, B, and C have black-height k + 1 in all cases. At left and in the middle, each of As and Bs subtrees
has black-height k and a black root, while C has one such subtree and a red child with black-height k + 1. At the right, each of
As and Cs subtrees has black-height k and a black root, while Bs red children each have black-height k + 1.

Page 6 of 7 PSU CMPSC 465 Spring 2013


Property 5 is preserved by the transformations. We have shown above that the black-height is well-defined within the
subtrees pictured, so property 5 is preserved within those subtrees. Property 5 is preserved for the tree containing the subtrees
pictured, because every path through these subtrees to a leaf contributes k + 2 black nodes.

Page 7 of 7 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 3: Chapter 18
CMPSC 465

Disclaimer: This is a draft of solutions that has been prepared by the TAs and the instructor makes no guarantees that
solutions presented here contain the level of detail that would be expected on an exam. Any errors or explanations you find
unclear should be reported to either of the TAs for corrections first.

Exercise 18.1-1
Why dont we allow a minimum degree of t = 1?

Solution:

According to the definition, minimum degree t means every node other than the root must have at least t 1 keys, and every
internal node other than the root thus has at least t children. So, when t = 1, it means every node other than the root must have
at least t 1 = 0 key, and every internal node other than the root thus has at least t = 1 child.

Thus, we can see that the minimum case doesn't exist, because no node exists with 0 key, and no node exists with only 1 child
in a B-tree.

Exercise 18.1-2
For what values of t is the tree of Figure 18.1 a legal B-tree?

Solution:

According to property 5 of B-tree, every node other than the root must have at least t1keys and may contain at most 2t1
keys. In Figure 18.1, the number of keys of each node (except the root) is either 2 or 3. So to make it a legal B-tree, we need
to guarantee that

t 1 2 and 2 t 1 3,

which yields 2 t 3. So t can be 2 or 3.

Exercise 18.1-3
Show all legal B-trees of minimum degree 3 that represent {1, 2, 3, 4, 5}.

Solution:

We know that every node except the root must have at least t 1 = 2 keys, and at most 2t 1 = 5 keys. Also remember that
the leaves stay in the same depth. Thus, there are 2 possible legal B-trees:

3
1, 2, 3, 4, 5
1, 2 4, 5

Page 1 of 4 PSU CMPSC 465 Spring 2013


Exercise 18.1-4
As a function of the minimum degree t, what is the maximum number of keys that can be stored in a B-tree of height h?

Solution:

A B-tree with maximum number of keys is shown below:

# of
depth nodes
2t 0 1
1
2
t

2t 2t
1
1 2t
1
2 2
t t

2t 2t 2t 2t 2 (2t)2
1 1 1 1
2 2 2 2
t t t t

2t 2t 2t 2t 2t 2t 2t 3 (2t)3
2t
1 1 1 1 1 1 1 1
We can see that each node contains 2t 1 keys, and at depth k, the tree at most has (2t)k nodes. The total nodes is therefore
the sum of (2t)0, (2t)1, (2t)2, (2t)3, , (2t)h. Let MaxKeyNum(t, h) as a function that returns the maximum number of keys in
a B-tree of height h and the minimum degree t. We can get that:
MaxKeyNum(t, h) = (2t 1)[(2t)0 + (2t)1 + (2t)2 + (2t)3 + + (2t) h] as [keys per node] * [total # of nodes]
= (2t 1) by using Sigma to sum up total # of nodes

= (2t 1) by the summation formula of geometric series

Exercise 18.1-5
Describe the data structure that would result if each black node in a red-black tree were to absorb its red children,
incorporating their children with its own.

Solution:

After absorbing each red node into its black parent, each black node may contain 1, 2 (1 red child), or 3 (2 red children) keys,
and all leaves of the resulting tree have the same depth, according to property 5 of red-black tree (For each node, all paths
from the node to descendant leaves contain the same number of black nodes). Therefore, a red-black tree will become a B-
tree with minimum degree t = 2, i.e., a 2-3-4 tree.

Page 2 of 4 PSU CMPSC 465 Spring 2013


Exercise 18.2-3
Explain how to find the minimum key stored in a B-tree and how to find the predecessor of a given key stored in a B-tree.

Solution:

Finding the minimum in a B-tree is quite similar to finding a minimum in a binary search tree. We need to find the left most
leaf for the given root, and return the first key.

B-TREE-FIND-MIN(x)
//PRE: x is a node on the B-tree T. The top level call is B-TREE-FIND-MIN(T.root).
//POST: FCTVAL is the minimum key stored in the subtree rooted at x.
{
if x == NIL //T is empty
{
return NIL
}
else if x.leaf //x is leaf
{
return x.key1 //return the minimum key of x
}
else
{
DISK-READ(x.c1)
return B-TREE-FIND-MIN(x.c1)
}
}

Finding the predecessor of a given key x.keyi is according to the following rules:

If x is not a leaf, return the maximum key in the i-th child of x, which is also the maximum key of the subtree rooted
at x.ci
If x is a leaf and i > 1, return the (i1)st key of x, i.e., x.keyi1
Otherwise, look for the last node y (from the bottom up) and j > 0, such that x.keyi is the leftmost key in y.cj; if j = 1,
return NIL since x.keyi is the minimum key in the tree; otherwise we return y.keyj1.

B-TREE-FIND-PREDECESSOR(x, i)
//PRE: x is a node on the B-tree T. i is the index of the key.
//POST: FCTVAL is the predecessor of x.keyi.
{
if ! x.leaf
{
DISK-READ(x.ci)
return B-TREE-FIND-MAX(x.ci)
}
else if i > 1 //x is a leaf and i > 1
return x.keyi1
else //x is a leaf and i = 1
{
z=x

while (1)
{
if z.p == NIL //z is root
return NIL // z.keyi is the minimum key in T; no predecessor

y = z.p
j=1
DISK-READ(y.c1)

Page 3 of 4 PSU CMPSC 465 Spring 2013


while (y.cj != x)
{
j=j+1
DISK-READ(y.cj)
}

if j == 1
z=y
else
return y.keyj1
}
}
}

B-TREE-FIND-MAX(x)
//PRE: x is a node on the B-tree T. The top level call is B-TREE-FIND-MAX(T.root).
//POST: FCTVAL is the maximum key stored in the subtree rooted at x.
{
if x == NIL //T is empty
{
return NIL
}
else if x.leaf //x is leaf
{
return (x, x.n) //return the maximum key of x
}
else
{
DISK-READ(x.cx.n+1)
return B-TREE-FIND-MAX(x.cx.n+1)
}
}

Exercise 18.2-6
Suppose that we were to implement B-TREE-SEARCH to use binary search rather than linear search within each node. Show
that this change makes the CPU time required O(lg n), independently of how t might be chosen as a function of n.

Solution:

As in the TREE-SEARCH procedure for binary search trees, the nodes encountered during the recursion form a simple path
downward from the root of the tree. Thus, the B-TREE-SEARCH procedure needs O(h) = O(logt n) CPU time to search along
the path, where h is the height of the B-tree and n is the number of keys in the B-tree, and we know that h . Since
the number of keys in each node is less than 2t 1, a binary search within each node is O(lg t). So the total time is:
O(lg t * logt n) = O(lg t * ) by changing the base of the logarithm

= O(lg n)

Thus, the CPU time required is O(lg n).

Page 4 of 4 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 4: Chapter 22
CMPSC 465

Disclaimer: This is a draft of solutions that has been prepared by the TAs and the instructor makes no guarantees that
solutions presented here contain the level of detail that would be expected on an exam. Any errors or explanations you find
unclear should be reported to either of the TAs for corrections first.

Exercise 22.1-1
Given an adjacency-list representation of a directed graph, how long does it take to compute the out-degree of every vertex?
How long does it take to compute the in-degrees?

Solution:

Given an adjacency-list representation Adj of a directed graph, the out-degree of a vertex u is equal to the length of Adj[u],
and the sum of the lengths of all the adjacency lists in Adj is |E|. Thus the time to compute the out-degree of every vertex is
(|V| + |E|).
The in-degree of a vertex u is equal to the number of times it appears in all the lists in Adj. If we search all the lists for each
vertex, the time to compute the in-degree of every vertex is (|V||E|).

(Alternatively, we can allocate an array T of size |V| and initialize its entries to zero. Then we only need to scan the lists in
Adj once, incrementing T [u] when we see u in the lists. The values in T will be the in-degrees of every vertex. This can be
done in (|V| + |E|) time with (|V|) additional storage.)

Page 1 of 8 PSU CMPSC 465 Spring 2013


Exercise 22.1-2
Give an adjacency-list representation for a complete binary tree on 7 vertices. Give an equivalent adjacency-matrix
representation. Assume that vertices are numbered from 1 to 7 as in a binary heap.

Solution:

A complete binary tree looks like:

1

2 3

4 5 6 7

An adjacency-list representation of this tree is shown below:

1 2 3

2 1 4 5

3 1 6 7

4 2
5 2
6 3

7 3

An equivalent adjacency-matrix representation of this tree is shown below:

1 2 3 4 5 6 7
1 0 1 1 0 0 0 0
2 1 0 0 1 1 0 0
3 1 0 0 0 0 1 1
4 0 1 0 0 0 0 0
5 0 1 0 0 0 0 0
6 0 0 1 0 0 0 0
7 0 0 1 0 0 0 0

Page 2 of 8 PSU CMPSC 465 Spring 2013


Exercise 22.2-1

Show the dist and pred values that result from running breadth-first search on the directed graph below, using vertex 3 as the
source. 1 2 3


Solution: 4 5 6

3.pred 3.pred
1 2 :NIL 1 2 :NIL
0 0

Q 3 Q 4

0 2
2 1 1

4 5 6 4.pred 5.pred 6.pred
:5 :3 :3
(a) (d)

3.pred 2.pred 3.pred


1 2 :NIL 1 :4 :NIL
3 0
0
Q 5 6 Q 2

1 1 3
2 1 1
1 1

4 5.pred 6.pred 4.pred 5.pred 6.pred
:3 :3 :5 :3 :3

(b) (e)

3.pred 2.pred 3.pred


1 2 :NIL 1 :4 :NIL
0 3 0

Q 6 4 Q
1 2
2 1 1 2 1 1

4.pred 5.pred 6.pred 4.pred 5.pred 6.pred
:5 :3 :3 :5 :3 :3

(c) (f)

The procedure of the breadth-first search is shown above. From the result, we can see that:

Node Pred dist


3 NIL 0
5 3 1
6 3 1
4 5 2
2 4 3
1 NIL

Page 3 of 8 PSU CMPSC 465 Spring 2013


Exercise 22.2-2

Show the dist and pred values that result from running breadth-first search on the undirected graph below, using vertex u as
the source. r s t u


v w x y
Solution:

u.pred s.pred t.pred u.pred


(a) r s t :NIL (f) r :w :u :NIL
0 3 1 0
Q u Q s
0 3
2 1
1
v w x y v w.pred x.pred y.pred
:t :u :u
t.pred u.pred r.pred s.pred t.pred u.pred
(b) r s :u :NIL (g) :s :w :u :NIL
1
0 4 3 1 0
Q t x y Q r
1 1 1 4
1
1
2 1
1
v w x.pred y.pred v w.pred x.pred y.pred
:u :u :t :u :u

t.pred u.pred r.pred s.pred t.pred u.pred


(c) (h)
r s :u :NIL :s :w :u :NIL
1 0 4 3 1 0
Q x y w Q v
1 1 2 5
2
1 1 5 2 1 1
v w.pred x.pred y.pred v.pred w.pred x.pred y.pred
:t :u :u :r :t :u :u

t.pred u.pred r.pred s.pred t.pred u.pred


(d) r s :u :NIL (i) :s :w :u :NIL
1 0 4 3 1 0
Q y w Q
1 2
2
1
1
5
2 1
1
v w.pred x.pred y.pred v.pred w.pred x.pred y.pred
:t :u :u :r :t :u :u
t.pred u.pred
(e) r s :u :NIL
1 0
Q w
2
2
1
1
v w.pred x.pred y.pred
:t :u :u

Page 4 of 8 PSU CMPSC 465 Spring 2013


The procedure of the breadth-first search is shown above. From the result, we can see that:

Node Pred dist


u NIL 0
t u 1
x u 1
y u 1
w t 2
s w 3
r s 4
v r 5

Exercise 22.3-1
Make a 3-by-3 chart with row and column labels WHITE, GRAY, and BLACK. In each cell (i, j), indicate whether, at any
point during a depth-first search of directed graph, there can be an edge from a vertex of color i to a vertex of color j. For
each possible edge, indicate what edge types it can be. Make a second such chart for depth-first search of an undirected graph.

Solution:

Directed graph:
WHITE GRAY BLACK
WHITE tree, back, forward, and cross back and cross cross
GRAY tree and forward tree, forward, back tree, forward, and cross
BLACK back and cross tree, forward, back and cross

Undirected graph:
WHITE GRAY BLACK
WHITE tree and back tree and back
GRAY tree and back tree and back tree and back
BLACK tree and back tree and back

Exercise 22.3-2
Show how depth-first search works on the graph of Figure 22.6. Assume that the for loop of lines 57 of the DFS procedure
considers the vertices in alphabetical order, and assume that each adjacency list is ordered alphabetically. Show the discovery
and finishing times for each vertex, and show the classification of each edge.

Page 5 of 8 PSU CMPSC 465 Spring 2013


Solution:

The discovery and finishing times for each vertex are shown in the figure below:
1,16 17,20

2,7 8,15 18,19

3,6 4,5 9,12 13,14

10,11

Tree edges: (q, s), (s, v), (v, w), (q, t), (t, x), (x, z), (t, y), (r, u)
Back edges: (w, s), (z, x), (y, q)
Forward edges: (q, w)
Cross edges: (r, y), (u, y)

Exercise 22.3-3
Show the parenthesis structure of the depth-first search of Figure 22.4.

Figure 22.4 (p)

Solution:

Exercise 22.3-7
Rewrite the procedure DFS, using a stack to eliminate recursion.

Solution:

Assume that the stack has following operations:


PUSH(S, v) pushes v into the stack;
POP(S) returns the top of the stack and removes it;
TOP(S) returns the top of the stack without removing it.

Page 6 of 8 PSU CMPSC 465 Spring 2013


Denote an empty stack by EMPTY.

Then the pseudocode of this algorithm becomes as follows:


DFS_STACK (G, s)
for each vertex u V(G) {s}
{
u.color = WHITE
u.pred = NIL
}
time = 0
S = EMPTY

time = time + 1
s.td = time
s.color = GRAY
PUSH(S, s)
while S != EMPTY
{
t = TOP(S)
if v V(G).Adj[t] s.t. v.color == WHITE // vs adjacency list hasnt been fully examined
{
v.pred = t
time = time + 1
v.td = time
v.color = GRAY
PUSH(S, v)
}
else // vs adjacency list has been fully examined
{
t = POP(S)
time = time + 1
v.tf = time
v.color = BLACK
}
}

Exercise 22.4-1
Show the ordering of vertices produced by TOPOLGICAL-SORT when it is run on the dag
of Figure 22.8, under the assumption of Exercise 22.3-2.

Solution:

According to the assumption of Exercise 22.3-2, the for loop of lines 57 of the DFS procedure

Page 7 of 8 PSU CMPSC 465 Spring 2013


considers the vertices in alphabetical order, and that each adjacency list is ordered alphabetically.

DFS on Figure 22.8:

1/20 21/26 22/25 27/28

2/5 23/24
6/19

3/4 7/8 10/17 11/14

9/18 12/13
15/16

Ordering of vertices:

Exercise 22.4-2
Give a linear-time algorithm that takes as input a directed acyclic graph G = (V, E) and two vertices s and t , and returns the
number of simple paths from s to t in G. For example, the directed acyclic graph of Figure 22.8 contains exactly four simple
paths from vertex p to vertex v: pov, poryv, posryv, and psryv.
(Your algorithm needs only to count the simple paths, not list them.)

Solution:

Add a field to the vertex representation to hold an integer count. Initially, set vertex ts count to 1 and other vertices count to
0. Start running DFS with s as the start vertex. When t is discovered, it should be immediately marked as finished (BLACK),
without further processing starting from it. Subsequently, each time DFS finishes a vertex v, set vs count to the sum of the
counts of all vertices adjacent to v. When DFS finishes vertex s, stop and return the count computed for s.

Page 8 of 8 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 4: Chapter 23
CMPSC 465

Disclaimer: This is a draft of solutions that has been prepared by the TAs and the instructor makes no guarantees that
solutions presented here contain the level of detail that would be expected on an exam. Any errors or explanations you find
unclear should be reported to either of the TAs for corrections first.

Exercise 23.1-2
Professor Sabatier conjectures the following converse of Theorem 23.1. Let G = (V, E) be a connected, undirected graph with
a real-valued weight function w defined on E. Let A be a subset of E that is included in some minimum spanning tree for G,
let (S, V S) be any cut of G that respects A, and let (u, v) be a safe edge for A crossing (S, V S). Then, (u, v) is a light edge
for the cut. Show that the professors conjecture is incorrect by giving a counterexample.

Solution:

That is false. A safe edge (with respect to the set of edges A) is defined to be any edge such that when we add it to A, we still
have a subset of some minimum spanning tree. This definition does not reference light edges in any way. In the situation
from a counterexample, there may be multiple safe edges from S to V S, not all of them have to be light.

A counterexample is shown below. Let S = {a, b, c}, A = {(a, b), (b, c}, we can see that (a, d), (b, e), (c, f) are all safe edges
for A crossing (S, V S), but only (b, e) is a light edge for the cut.

1 1
a b c

3 1 5 4
d 5
e f

Exercise 23.1-3
Show that if an edge (u, v) is contained in some minimum spanning tree, then it is a light edge crossing some cut of the graph.

Solution:

Suppose (u, v) T, a minimal spanning tree. Let A = {T (u, v)}. A contains two trees: A = Tu Tv. Tu is the tree in which
vertex u appears, and Tv is the tree in which vertex v appears. Moreover, Vu Vv = V, where Vu contains the vertices of Tu
and Vv contains the vertices of Tv. That is, (Vu, Vv) is a cut, which is crossed by (u, v) and which respects A. Any edge crossing
the cut rejoins the two trees. If there is a crossing edge (x, y) with w(x, y) < w(u, v), then T = Tu Tv (x, y) is a spanning
tree with weight:
w(T) = w(Tu Tv) + w(x, y) as T = Tu Tv (x, y)
= w(Tu Tv) + w(u, v) + [w(x, y) w(u, v)] by adding 0, that is w(u, v) w(u, v)
= w(T) [w(u, v) w(x, y)] as T = Tu Tv (u, v)
< w(T)

This contradicts with that (u, v) is contained in some minimum spanning tree. So, w(u, v) < w(x, y) for all (x, y) crossing the
cut (Vu, Vv). That is, (u, v) is a light edge crossing the cut.

Exercise 23.2-1
Kruskals algorithm can return different spanning trees for the same input graph G, depending on how it breaks ties when the
edges are sorted into order. Show that for each minimum spanning tree T of G, there is a way to sort the edges of G in
Kruskals algorithm so that the algorithm returns T.

Page 1 of 1 PSU CMPSC 465 Spring 2013


Solution:

We would start by sorting the edges in of G in non-descending order. In addition, we would want that among the edges of
same weight, the edges which are contained in T are placed in first positions.

Exercise 23.2-8
Professor Borden proposes a new divide-and-conquer algorithm for computing minimum spanning trees, which goes as
follows. Given a graph G = (V, E), partition the set V of vertices into two sets V1 and V2 such that |V1| and |V2| differ by at
most 1. Let E1 be the set of edges that are incident only on vertices in V1, and let E2 be the set of edges that are incident only
on vertices in V2. Recursively solve a minimum-spanning-tree problem on each of the two subgraphs G1 = (V1, E1) and G2 =
(V2, E2). Finally, select the minimum-weight edge in E that crosses the cut (V1, V2), and use this edge to unite the resulting
two minimum spanning trees into a single spanning tree.
Either argue that the algorithm correctly computes a minimum spanning tree of G, or provide an example for which the
algorithm fails.

Solution:

We argue that the algorithm fails. Consider the graph G below. We partition G into V1 and V2 as follows: V1 = {A, B}, V2 = {C,
D}. E1 = {(A, B)}. E2 = {(C, D)}. The set of edges that cross the cut is Ec = {(A, C), (B, D)}.

1
A B
G1
2 3
G2
C D
8

Now, we must recursively find the minimum spanning trees of G1 and G2. We can see that in this case, MST(G1) = G1 and
MST(G2) = G2. The minimum spanning trees of G1 and G2 are shown below on the left.

The minimum weighted edge of the two edges across the cut is edge (A, C). So (A, C) is used to connect G1 and G2. This is
the minimum spanning tree returned by Professor Bordens algorithm. It is shown below and to the right.
1 1
A B A B
G1
2 3 2 3
G2
C D C D
8 8
We can see that the minimum-spanning tree returned by Professor Bordens algorithm is not the minimum spanning tree of G,
therefore, this algorithm fails.

Page 2 of 2 PSU CMPSC 465 Spring 2013


Homework Solutions Unit 4: Chapter 24
CMPSC 465

Disclaimer: This is a draft of solutions that has been prepared by the TAs and the instructor makes no guarantees that
solutions presented here contain the level of detail that would be expected on an exam. Any errors or explanations you find
unclear should be reported to either of the TAs for corrections first.

Exercise 24.3-1
Run Dijkstras algorithm on the directed graph below, first using vertex s as the source and then using vertex z as the source.
In the style of Figure 24.6, show the d and values and the vertices in set S after each iteration of the while loop.

Solution:

Omitted

Exercise 24.3-3
Suppose we change line 4 of Dijkstras algorithm to the following:
line 4: while |Q| > 1

This change causes the while loop to execute |V| 1 times instead of |V| times. Is this proposed algorithm correct?

Solution:

Yes, the algorithm still works. Let u be the leftover vertex that does not get extracted from the priority queue Q. If u is not
reachable from s, then d[u] = (s, u) = . If u is reachable from s, there is a shortest path p = s ~ x u. When the node x was
extracted, d[x] = (s, x) and then the edge (x, u) was relaxed; thus, d[u] = (s, u).

Page 1 of 1 PSU CMPSC 465 Spring 2013


Design and Analysis of Algorithms, Fall 2014
Exercise I: Solutions

I-1 Let T (n) = M for n M for some constant M 1 independent of n, and 2T (n) = 2T (n/2) + 3T (n/3) + n
otherwise. Show that T (n) = (n log n).
As a clarification, we assume that the recurrence is defined for all positive reals. To show T (n) = (n log n),
we show separately that T (n) = O(n log n) and T (n) = (n log n). All logarithms used are 2-based.
For the O direction, we show by induction that T (n) n log n + cn = (n log n) for n 1/3 for some
c > 0.
1. Case 1/3 n M: Its easy to see that n log n is bounded from below by some constant c0 . Now, if
we choose any c 3(M c0 ), we have that T (n) = M c0 + (1/3)c n log n + cn.
2. Induction step n > M: assume that the claim holds for n/2 and n/3. Note that, since M 1, the
smallest n for which the claim is assumed to hold is 1/3, which is proven in the base case. Under these
assumptions, we have that
2T (n) = 2T (n/2) + 3T (n/3) + n
2( 2n log n2 + n2 c) + 3( 3n log n3 + n3 c) + n induction assumption
= n(log n2 + log 3n + 1) + 2nc
= n(2 log n log 6 + 1) + 2nc properties of logarithm
2(n log n + nc) log2 6 > 1
holds regardless of our choice of c.
For the direction, we show by induction that T (n) cn log n = (n log n) for some c > 0.
1. Case n M: by choosing c 1/ log M, we have that T (n) = M cM log M cn log n.
2. Induction step n > M: assume that the claim holds for n/2 and n/3. Then,
2T (n) = 2T (n/2) + 3T (n/3) + n
2(c 2n log n2 ) + 3(c n3 log n3 ) + n induction assumption
= 2cn log n + n(1 c log 6) properties of logarithm
2cn log n
where the last inequality holds if 1 c log 6 0 c 1/ log 6.
Since we want both of steps 1 and 2 to hold, we can choose c = min(1/ log M, 1/ log 6).

I-2 (CLRS 2.3-7) Describe a (n log n)-time algorithm that, given a set S of n integers and another integer x,
determines whether or not there exist two elements in S whose sum is exactly x.
Sort the set S using merge sort. Then for each y S separately use binary search to check if integer x y
exists in S. Sorting takes time (n log n). Binary search takes time O(log n) and is executed n times. The
total time is thus (n log n).
If S is sorted, the problem can also be solved in linear time by scanning the list S at the same time forward
and backward directions:
Input: list S sorted in ascending order, x
Output: true if there exist two elements in S whose sum is exactly x, false otherwise
1 i 1, j n
2 while i j do
3 if S[i] + S[ j] = x then
4 return true
5 if S[i] + S[ j] < x then
6 i i+1
7 else
8 j j1
9 return false

1
Note: The above solutions assume that the two elements can actually be the same element (for examples, if
S = {1, 2, 5} and x = 4, the algorihms return true since 2 + 2 = 4). If this is not allowed, then small changes
to algorithms are needed. (In the first solution skip y if 2y = x. In the second solution replace by <.)

I-3 (CLRS 2-4 Inversions) Let A[1..n] be an array of n distinct numbers. If i < j and A[i] > A[ j], then the pair
(i, j) is called an inversion of A.

a. List the five inversions of the array (2, 3, 8, 6, 1).


(1,5), (2,5), (3,4) (3,5), (4,5)
b. What array with elements from the set {1, 2, . . . , n} has the most inversions? How many does it have?
If the array is sorted in descending order, then every pair (i, j) with i < j is an inversion. The number
of such pairs is n(n 1)/2.
c. What is the relationship between the running time of insertion sort and the number of inversions in the
input array? Justify your answer.
Assume a version of insertion sort that does not use a temporary variable but instead uses swaps to
move the current element into the correct place in the already sorted part of the array. Now each
execution of the inner loop body (that is, each swap) eliminates one inversion. Sorting eliminates all
inversion and therefore the inner loop is executed exactly I times, where I is the number of inversions
in the array. Since the outer loop is executed n times the total running time is (I + n).
d. Give an algorithm that determines the number of inversions in any permutation of n elements in
(n log n) worst-case time. (Hint: Modify merge sort.)
We modify merge sort to count the number of inversion while sorting the array. The number of
inversion in array A = BC is
I(A) = I(B) + I(C) + I(B,C),
where I(X) is the number of inversion in array X and I(X,Y ) is the number of pairs (x, y) X Y such
that x > y. Let head(X) be the first element in array X. We can compute term I(B,C) in the following
way while merging arrays B and C:
If head(B) head(C), we append head(B) to the merged array and remove it from array B as
usual.
If head(B) > head(C), we append head(C) to the merged array, remove it from array C, and
increment I(B,C) by the number of elements remaining in array B.
Terms I(B) and I(C) are computed recursively. Counting the number of inversions does not increase
the asymptotic time complexity of the merge sort.

I-4 (CLRS 4.2-6) How quickly can you multiply a knn matrix by an nkn matrix, using Strassens algorithms
as a subroutine? Answer the same question with the order of input matrices reversed.
Let the input be A = [AT1 ATk ]T and B = [B1 Bk ], where Ai and Bi are n n submatrices. The product
AB is a kn kn matrix
A1 B1 A1 Bk
AB = ... .. .. ,

. .
Ak B1 Ak Bk
where each product Ai B j can be computed in (nlog2 7 )
time using Strassens algorithm. There are k2 such
2 log 7
products, so the total time requirement is (k n 2 ).
The product BA is a n n matrix BA = ki=1 Ai Bi . There are k products requiring (nlog2 7 ) time and k 1
summations requiring (n2 ) time. The total time is thus (knlog2 7 ).

2
I-5 (CLRS 4.2-7) Show how to multiply the complex numbers a + bi and c + di using only three multiplications
of real numbers. The algorithm should take a, b, c, and d as input and produce the real component ac bd
and the imaginary component ad + bc separately.
Compute the products ac, bd and (a + b)(c + d). Now the real component is ac bd and imaginary com-
ponent is (a + b)(c + d) ac bd.
Alternatively, compute e.g. a(c d), d(a b) and b(c + d). Now the real component is obtained as the sum
of the first two, and the imaginary component as the sum of the last two.
Both solutions use 3 multiplications and 5 additions/substractions.

3
Design and Analysis of Algorithms, Fall 2014
Exercise II: Solutions

II-1 Where in the matrix multiplication-based DP algorithm for the all-pairs shortest paths problem do we need
the associativity of matrix multiplication?
The algoritm computes the product W n1 with the exception that instead of the usual definition, the product
of matrices A and B is defined by

A B = C, where Ci j = min{Aik + Bk j }.
k

The slow version of the algorithm uses a recurrence W i+1 = W i W , which gives the correct result. The fast
version uses repeated squaring: W 2i = W i W i . We do not know a priori that the second recurrence computes
W 2i correctly. However, from the associativity of multiplication it follows that W i W i = W 2i1 W , that is,
the fast version works correctly.

II-2 Give an O(n2 )-time algorithm to find the maximum length of monotonically increasing subsequences of a
given sequence of n numbers. For instance, if given (3, 1, 2, 5, 2, 6, 8, 6, 7, 3, 5) as input, the algorithm should
output 6 (the length of the subsequence (1, 2, 5, 6, 6, 7)). (Side note: Even an O(n log n)-time algorithm
exists.)
We write MIS short for monotonically increasing subsequence. Let A[i] denote the ith number in the
sequence. For all 1 i n we define L[i] as the length of the longest MIS that ends in A[i]. Then L[1] = 1
and for all i > 1 we have that

L[i] = max{L[k] : 1 k i 1, A[k] A[i]} + 1.

In other words, L[i] is found by finding the longest MIS among the preceding numbers that can be continued
by A[i]. Assuming the values L[k] for 1 k i 1 are already computed, L[i] is easily computed in linear
time. This yields a simple dynamic programming algorithm that computes all L[i] in increasing order of i in
O(n2 ) time. The solution is then obtained as max{L[i] : 1 i n}. To find the actual longest MIS (instead
of just the length), the algorithm should also keep track of the maximizing indices k, which can then be used
to reconstruct the MIS.
The problem can also be solved in O(n log n) time by formulating the dynamic programming in a different
manner. The algorithm initializes an array E and performs n iterations, maintaining the following invariant:
After the ith iteration, each E[`] for 1 ` i contains the smallest number that ends a MIS of length exactly
` among the first i elements of A, or if no such subsequence exists.
Assuming the invariant holds, its easy to see that E is always increasing: If theres a MIS of length ` ending
at A[i], theres also a MIS of length ` + 1 ending at A[ j] for A[i] < A[ j]. Therefore A[i] couldnt be the
smallest number that ends a MIS of length `.
To maintain the invariant, for iteration i the algorithm uses binary search to find the largest E[`] A[i]. Since
E[`] ends a MIS of length `, it is extended by A[i] to produce a MIS of length ` + 1, and A[i] is clearly the
smallest number ending such a MIS so far. Hence, the algorithm updates E[` + 1] = A[i]. If no E[`] A[i]
exists, the algorithm updates E[1] = A[i]. It turns out no other changes are required.
Therefore, for each of the n iterations the algorithm performs a O(log n) amount of work, giving the claimed
time complexity. After all iterations, the answer is the largest index k for which L[k] < . Again, slight
modifications are required to find the actual MIS.

1
II-3 (CLRS 15-3 Bitonic euclidean traveling-salesman problem) The euclidean traveling-salesman problem
is the problem of determining the shortest closed tour that connects a given set of n points in the plane.
Figure 15.11(a) shows the solution to a 7-point problem. The general problem is NP-complete, and its
solution is therefore believed to require more than polynomial time (see Chapter 34).
J. L. Bentley has suggested that we simplify the problem by restricting our attention to bitonic tours, that is,
tours that start at the leftmost point, go strictly left to right to the rightmost point, and then go strictly right
to left back to the starting point. Figure 15.11(b) shows the shortest bitonic tour of the same 7 points. In
this case, a polynomial-time algorithm is possible.
Describe an O(n2 )-time algorithm for determining an optimal bitonic tour. You may assume that no two
points have the same x-coordinate. (Hint: Scan left to right, maintaining optimal possibilities for the two
parts of the tour.)
The first step is to sort the points according to x-coordinate. Let the sorted points be 1, . . . , n and let d(i, j)
be the distance between points i and j.
A bitonic tour starts at the leftmost point and ends at the rightmost point. It consists of two paths, the upper
and lower (imaging a line connecting the starting and end points), such that each point is visited by at least
one of the paths. We describe a dynamic programming algorithm which uses partially constructed bitonic
tours.
For i, j {1, . . . , n} and i, j on separate paths, let B[i, j] be the minimum total cost of two paths. Now the
length of the optimal bitonic tour is given by B[n, n]. Since B[i, j] = B[ j, i], we are only interested in pairs
i, j with 1 i j n. The base case is B[1, 1] = 0. For the rest of the cases we compute B[i, j] as follows
(the idea is deciding the predecessor of point j):
Case 1: If i < j 1, then the path ending in j must also visit j 1, because the other path cannot visit
j 1 and then backtrack to i. Thus we have

B[i, j] = B[i, j 1] + d( j 1, j), if i < j 1.

Case 2: If i = j 1 or i = j, then the optimal solution must have a path which ends in j and comes
from some node k with 1 k < j. The optimal solution is therefore given by selecting the optimal
predecessor by setting
B[i, j] = min {B[i, k] + d(k, j)}.
1k< j

where B[i, k] can be replaced by B[k, i] (already computed), since B[i, j] = B[ j, i].

There are O(n2 ) entries that fall under the first case, and each of these takes a constant time to handle. The
second case occurs only O(n) times, with each taking O(n) time. Therefore the total running time is O(n2 ).
To get the actual optimal bitonic tour, we modify the algorithm to keep track of the optimal predecessor
chosen in the case 2 in a separate table. The optimal tour can then be constructed from this information.

II-4 (CLRS 15-4 Printing neatly) Consider the problem of neatly printing a paragraph on a printer. The input
text is a sequence of n words of lengths l1 , l2 , . . . , ln , measured in characters. We want to print this paragraph
neatly on a number of lines that hold a maximum of M characters each. Our criterion of neatness is as
follows. If a given line contains words i through j, where i < j, and we leave exactly one space between
j
words, the number of extra space characters at the end of the line is M j + i k=i lk , which must be non-
negative so that the words fit on the line. We wish to minimize the sum, over all lines except the last, of the
cubes of the numbers of extra space characters at the ends of lines. Give a dynamic-programming algorithm
to print a paragraph of n words neatly on a printer. Analyze the running time and space requirements of
your algorithm.
Let
j
s(i, j) = M j + i + 1 lk
k=i+1

2
be the number of trailing spaces required when the words i + 1, . . . , j are put on a same line. Observe that is
possible to put these words on a line only if s(i, j) 0. We define the cost of putting the words from i + 1
to j on a same line as
,
if s(i, j) < 0
c(i, j) = 0, if j = n and s(i, j) 0

s(i, j)3 , otherwise.

The dynamic programming is now straightforward to formulate. Let C[ j] be the optimal cost of printing the
words from 1 to j, such that word j ends a line. Then we have

C[0] = 0
C[ j] = min {C[i] + c(i, j)} for j > 0.
0i< j

Computing C takes (n2 ) time, as c(i 1, j) can be computed from c(i, j) in constant time. The space
requirement is (n). A straightforward modification gives us O(Mn) time, as there cannot be more than
(M + 1)/2 words on a single line.
Again, to actually get the optimal line lengths and print the paragraph, we need to keep track of minimizing
values i, which indicate the last word on the previous line, given that the last word on the current line is j.

II-5 (CLRS 25.1-9) Modify Faster-All-Pairs-Shortest-Paths so that it can determine whether the graph contains
a negative-weight cycle.
We observe that if the graph contains a negative-weight cycle, then there is a negative-weight path of length
k n from some vertex i to i. This means that in the matrix-multiplication-based all-pairs shortest path
algorithm we will get a negative value on the diagonal of the matrix W m for all m k. Therefore we can
detect the existence of negative cycles simply by checking whether there are negative values on the diagonal
dlog ne
of the matrix W 2 2 . Note that we have to modify the algorithm to compute matrices up to at least W n
instead of W n1 , as the shortest negative weight cycle might have length n.

3
Design and Analysis of Algorithms, Fall 2014
Exercise III: Solutions

III-1 Show that the subset-sum problem is solvable in polynomial time if the target value t is expressed in unary.
Let Si , . . . , Sn be the sequence of positive integers. We want to find out if there is a (multi-)subset of S that
sums up to t > 0. For all 0 i n and 0 p t, we define L[i, p] to be true if there is a subset of S1 , . . . , Si
that sums up p, and false otherwise. Then L[n,t] is the solution to the problem. Observe that L[i, 0] is true
for all, i and L[0, p] is false for all p > 0. For i 1 and p 1, there is a subset of S1 , . . . , Si summing up to
p if and only if there is a subset of S1 , . . . , Si1 summing to either p or p Si . Thus, we get

true if p = 0
L[i, p] = false if p > 0 and i = 0
L[i 1, p] L[i 1, p Si ] otherwise.

The term L[n,t] is easily evaluated in O(nt) time using dynamic programming. Let b be the size of the
input in bits. If t is expressed in binary, as is common, then b = O(log2 t) and the running time is O(2b n).
However, if we express t in unary, then b = O(t) and the running time is O(nb), which is polynomial in the
input b.

III-2 (CLRS 34.1-5) Show that if an algorithm makes at most a constant number of calls to polynomial-time
subroutines and performs an additional amount of work that also takes polynomial time, then it runs in
polynomial time. Also show that a polynomial number of calls to polynomial-time subroutines may result
in an exponential-time algorithm.
Let k be the number of subroutines. The algorithm starts out with an input data of size n. Each subroutine
takes (some of) the available data as an input, performs some steps, then returns some amount of data as an
output. Every time a subroutine returns, the output accumulates the amount of data the algorithm has access
to. Any or all of this data may then be given as an input to the next subroutine. Since each subroutine runs
in polynomial time, the output must also have a size polynomial in the size of the input. Let d be an upper
bound on the degree of the polynomials. Then there is a function p(n) = nd + c, where c is a constant, such
that p(n) is an upper bound for the size of the output of any subroutine when given an input of size n.
Let n0 = n and ni = ni1 + p(ni1 ) for all 1 i k. We show by induction that ni is an upper bound for
the amount of data available to the algorithm after the ith subroutine call. The base case is trivial. Assume
the claim holds for i 1 and let n0 be the exact amount of data available before the ith call. Then we have
ni n0 + p(n0 ), since the ith call accumulates the amount of the data by at most p(n0 ). Since p is increasing,
by assumption we have n0 ni1 and p(n0 ) p(ni1 ), from which the claim follows.
We use induction again to show that each ni is polynomial in n. The base case is again trivial. Assume ni1
is polynomial in n. Since the composition of two polynomials is also polynomial, we have that p(ni1 ) is
polynomial in n. Since also the sum of two polynomials is polynomial, we have that ni1 + p(ni1 ) = ni is
polynomial in n. Therefore nk , which is an upper bound for the amount of data after the final subroutine, is
also polynomial in n, and the time must also be polynomial.
For the second part, observe that if we have a subroutine whose output is always twice the size of its input,
and we call this subroutine n times, starting with input of size 1 and always feeding the previous output back
into the subroutine, the final output will have size 2n . This means that the algorithm will take exponential
time.

III-3 (CLRS 34.5-8) In the half 3-CNF satisfiability problem, we are given a 3-CNF formula with n variables
and m clauses, where m is even. We wish to determine whether there exists a truth assignment to the
variables of such that exactly half the clauses evaluate to 0 and exactly half the clauses evaluate to 1.
Prove that the half 3-CNF satisfiability problem is NP-complete. (You may assume that the 3-CNF formula
has at most 3 literals per clause, not necessarily exactly 3.)
First observe that given a 3-CNF formula and an assignment, it is easy to check in polynomial time if the
assignment satisfies exactly half of the clauses. Therefore the half 3-CNF satisfiability is in NP.

1
We show NP-completeness by reduction from 3-CNF satisfiability. Let be a 3-CNF-SAT formula with
n variables and m clauses. We construct a 3-CNF-SAT formula such that exactly half of the clauses in
can be satisfied if and only if can be satisfied. Suppose that yi and zi for i = 1, . . . , m + 1 as well as p
are variables that do not appear in . We add to by all the clauses of , m(m + 1) + 1 distinct clauses
of form {q, q, p}, where q can be any variable (we call these type 1 clauses) and clause {yi , z j , p} for all
i, j {1, . . . , m + 1} (we call these type 2 clauses). Constructing clearly takes polynomial time.
We observe that all type 1 clauses are always satisfied. Since there are total of 2(m + 1)2 clauses, we have
to satisfy precisely m other clauses to satisfy half of the clauses of . If we tried to satisfy any type 2 clause
{yi , z j , p}, we would also satisfy all type 2 clauses with variable yi or all type 2 clauses with variable z j . This
means that we would satisfy at least m + 1 additional clauses, that is, total of at least (m + 1)2 + 1 clauses.
Thus the only way to satisfy exactly (m + 1)2 clauses in is to satisfy all the clauses of . This implies that
exactly half of the clauses in can be satisfied if and only if can be satisfied.
Thus, given a polynomial-time algorithm for the half 3-CNF-SAT problem, we could solve 3-CNF-SAT in
polynomial time. Since we know 3-CNF-SAT to be NP-complete, it follows that the half 3-CNF-SAT is
NP-complete as well.

III-4 (CLRS 34.4-6) Suppose someone gives you a polynomial-time algorithm to decide formula satisfiability.
Describe how to use this algorithm to find satisfying assignments in polynomial time.
Let be the input SAT formula that is satisfiable and contains n variables. Let |xi =0 and |xi =1 be the
simplified SAT formulas obtained by replacing variable xi by values 0 and 1 respectively and eliminating
constants 0 and 1 by partially evaluating the formula. These can be computed in polynomial time. The
results are SAT formulas containing n 1 variables. For example, if = ((x1 x2 ) ((x1 x3 )
x4 )) x2 then

|x2 =0 = ((x1 0) ((x1 x3 ) x4 )) 0 = (x1 ((x1 x3 ) x4 )) and


|x2 =1 = ((x1 1) ((x1 x3 ) x4 )) 1 = 0.

Clearly is satisfiable by assignment containing xi = c if and only if |xi =c is satisfiable. The algorithm
now takes any variable xi and asks the oracle whether |xi =0 is satisfiable. If the answer is yes, then the
algorithm sets xi = 0 and recursively repeats the procedure with |xi =0 . Otherwise |xi =1 must be satisfiable,
so the algorithm sets xi = 1 and recursively repeats the procedure with |xi =1 . Once all variables have been
assigned a value, this assignment satisfies the original SAT formula. The algorithm takes n polynomial time
steps and thus works in polynomial time.
Instead of reducing the formula, one may alternatively augment it with conjunctions, producing formulas of
form xi and xi . Again, one consults the oracle and recurses on a satisfiable formula until for each
variable either the variable or its negation has been added, yielding a satisfying assignment.

III-5 (CLRS 34.5-6) Show that the hamiltonian-path problem is NP-complete. (You may assume that you know
that HAM-CYCLE is NP-complete.)
Again, observe that given a sequence of vertices it is easy to check in polynomial time if the sequence is a
hamiltonian path, and thus the problem is in NP.
We reduce from the hamiltonian cycle problem. Let G = (V, E) be a graph. The reduction transforms graph
G into G0 as follows. We pick an arbitrary vertex v V and add a new vertex v0 that is connected to all the
neighbors of v. We also add new vertices u and u0 so that u is adjacent to v and u0 is adjacent to v0 . This
reduction clearly takes a polynomial time.
To complete the proof, we have to show that G has a hamiltonian cycle if and only if G0 has a hamiltonian
path. Now if there is a hamiltonian cycle (v, v2 , . . . , vn , v) in G, then (u, v, v2 , . . . , vn , v0 , u0 ) is a hamiltonian
path in G0 . On the other hand, if there is a hamiltonian path in G0 , its endpoints have to be u and u0 ,
because these have only on neighbor and thus cannot be in a middle of the path. Thus, the path has form
(u, v, v2 , . . . , vn , v0 , u0 ) and we have that (v, v2 , . . . , vn , v) is a hamiltonian cycle in G.

2
Design and Analysis of Algorithms, Fall 2014
Exercise IV: Solutions

IV-1 (CLRS 17.1-1) If the set of stack operations included a M ULTIPUSH operation, which pushes k items onto
the stack, would the O(1) bound on the amortized cost of stack operations continue to hold?
No. The time complexity of such a series of operations depends on the number of pushes (pops vise versa)
could be made. Since one M ULTIPUSH needs (k) time, performing n M ULTIPUSH operations, each with
k elements, would take (kn) time, leading to amortized cost of (k).

IV-2 (CLRS 17.1-3) Suppose we perform a sequence of n operations on a data structure in which the ith operation
costs i if i is an exact power of 2, and 1 otherwise. Use aggregate analysis to determine the amortized cost
per operation.
In a sequence of n operations there are blog2 nc + 1 exact powers of 2, namely 1, 2, 4, . . . , 2blog2 nc . The total
blog nc
cost of these is a geometric sum i=0 2 2i = 2blog2 nc+1 1 2log2 n+1 = 2n. The rest of the operations are
cheap, each having a cost of 1, and there are less than n such operations. The total cost of all operations is
thus T (n) 2n + n = 3n = O(n), which means O(1) amortized cost per operation.

IV-3 (CLRS 17.2-2 and CLRS 17.3-2) Redo the previous exercise using (a) an accounting method of analysis
and (b) a potential method of analysis.

(a) The actual cost of the ith operation is


(
i if i is an exact power of 2
ci =
1 otherwise.
We assign the amortized costs as follows:
(
2 if i is an exact power of 2
ci =
3 otherwise.

Now an operation, which is an exact power of 2 uses all previously accumulated credit plus one unit
of its own amortized cost to pay its true cost. It then assigns the remaining unit as credit. On the other
hand, if i is not an exact power of 2, then the operation uses one unit to pay its actual cost and assigns
the remaining two units as credit. This covers the actual cost of the operation. We still have to show
that there will always be enough credit to pay the cost of any power-of-2 operation. Clearly this is
the case for the first operation (i = 1), which happens to be an exact power of two. Let now j > 0.
After 2 j1 :th operation there is one unit of credit. Between operations 2 j1 and 2 j there are 2 j1 1
operations none of which is an exact power of 2. Each assigns two units as credit resulting to total of
1 + 2 (2 j1 1) = 2 j 1 accumulated credit before 2 j th operation. This, together with one unit by
its own, is just enough to cover its true cost. Therefore the amount of credit stays nonnegative all the
time, and the total amorized cost is an upper bound for the total actual cost.
(b) We define the potential function as follows:
(D0 ) = 0 and (Di ) = 2i 2blog2 ic+1 + 1 for i > 0.
(Note that (Di ) actually equals to the amount of credit after ith operation in previous exercise.)
This potential is always nonnegative, so we have (Di ) 0 = (D0 ) for all i. Now
For i, which is an exact power of 2, the potential difference is
(Di ) (Di1 ) = (2i 2i + 1) (2(i 1) i + 1) = 2 i
Note that this also holds for i = 1. Thus, the amortized cost of ith operation is
ci = ci + (Di ) (Di1 ) = i + 2 i = 2.

1
For i, which is not an exact power of 2, the potential difference is
(Di ) (Di1 ) = (2i i + 1) (2(i 1) i + 1) = 2.
Thus, the amortized cost of ith operation is
ci = ci + (Di ) (Di1 ) = 1 + 2 = 3.
As seen above, the amortized cost of each operation is O(1).

IV-4 (CLRS 17.3-4) What is the total cost of executing n of the stack operations P USH, P OP, and M ULTIPOP,
assuming that the stack begins with s0 objects and finishes with sn objects?
Let be the potential function that returns the number of elements in the stack. We know that for this po-
tential function, we have amortized cost 2 for P USH operation and amortized cost 0 for P OP and M ULTIPOP
operations.
The total amortized cost is
n n
ci = ci + (Dn ) (D0 ).
i=1 i=1
Using the potential function and the known amortized costs, we can rewrite the equation as
n n
ci = ci + (D0 ) (Dn )
i=1 i=1
n
= ci + s0 sn
i=1
2n + s0 sn ,
which gives us the total cost of O(n + (s0 sn )). If sn s0 , then this equals to O(n), that is, if the stack
grows, then the work done is limited by the number of operations.
(Note that it does not matter here that the potential may go below the starting potential. The condition
(Dn ) (D0 ) for all n is only required to have ni=1 ci ni=1 ci , but we do not need for that to hold in
this application.)

IV-5 (CLRS 17.4-3) Suppose that instead of contracting a table by halving its size when its load factor drops
below 1/4, we contract it by multiplying its size by 2/3 when its load factor drops below 1/3. Using the
potential function (T ) = |2 N(T ) S(T )|, show that the amortized cost of a TABLE -D ELETE that uses
this strategy is bounded above by a constant. Here N(T ) and S(T ) denote the number of items stored in
table T and the size of T , respectively.
Let ci denote the actual cost of the ith operation, ci its amortized cost and ni , si and i the number of items
stored in the table, the size of the table and the potential after the ith operation, respectively. The potential
i cannot get negative values and we have 0 = 0. Therefore i 0 for all i and the total amortized cost
provides an upper bound on the actual cost.
Now if the ith operation is TABLE -D ELETE, then ni = ni1 1. Consider first the case when the load factor
ni
does not drop below 1/3, i.e. si1 31 . Then the table isnt contracted and si = si1 . We pay ci = 1 for
deleting one item. Thus
ci = ci + i i1
= 1 + |2ni si | |2ni1 si1 |
= 1 + |2ni1 si1 2| |2ni1 si1 | ni = ni1 1, si = si1
1 + |(2ni1 si1 2) (2ni1 si1 )| (reverse) triangle inequality
= 1+2 = 3

2
Now consider the case when the load factor drops below 1/3, i.e.

ni 1 ni1 2
< 2ni < si1 2ni + 2. (1)
si1 3 si1 3
Now we contract the table and have
2 2
si = b2/3 si1 c si1 1 si si1 . (2)
3 3
By combining (1) and (2) we get 2ni 1 si 2ni + 2 and thus |2ni si | 2. Furthermore, from (1) we
get si1 > 3ni and thus |2ni1 si1 | = 2ni1 + si1 ni1 . We pay ci = ni + 1 for deleting one item and
moving the remaining ni items into the contracted table. Then,

ci = ci + i i1
= (ni + 1) + |2ni si | |2ni1 si1 |
(ni + 1) + 2 ni = 3

In both cases the amortized cost is at most 3 and thus bounded above by a constant.

3

 !"#$&%
'
(*),+-/.!01+3254768.:9<;=0?>A@CB/DEDEF
GIHAJK^CGMLl|N*hOQq}_?PS]QRUlUTW^{VXvpJZ`~Y\[\`{]Qcr]b^=_1^=`7"aAa1bbQcd`~a*Wef^=ctstsgQ^{hjuq}ikgcdlU`k_?aAccd_1a1mZ`{non]Q`{g,a1^paAa1_<qsx rEctstsmu]^=_1qsa1qwv=`=xzySlU^{v=`
G - Jj-/p+ eGwi\GwJ\ J3fGwi,Gs\ 9<JI>|J8z-/aA*b`{Cg-U.:i,>Gs-/\*J*{ f;pGMe01> Gwu\JI J@zxu. z 0?7eGs\ -/J~ 0E7i, zGs\eJGw\ 9<J*>-<H
Cf-/G}.!eGs>\-/JI"J {z ;p0?01K> . 01@>!0u 9 -/>:e0fGw-|\J3p-U.!Cf>:-<GwQi,{Gs\JIJ ;p01>
9U& 01-/<C01+>1@ -| 6?)C9<)p9 .: -<0 X.iGw5\J D
G ; J-eCGw6\ J .G$H -Ui- . GwJ \~ J3P i)Gw)=f\9 JG 0 Z. e-UeGs. \Gs\JeJ8GwI\i,JGs\ J9<>*iJGw-<x \ JuzKufGu @ -/Z  0<e6 |Gw\O J"$0i. fGw\e )pJ9 U-/!Jp! + ;Czi 0E ;p01 0
.e Gw0?\>:J0-/i>:Gw0\-JC -U.:, >-/ = XeCGw\;=J8I0?i,> Gs\ J-<C+5 - 9<6?>Q9<-/ .:-<X.7 @D  p 6 6 . -/. )=9 :! ;H0<
G 6 Jjea1bQGs\`XJ7g 9<f GMGwei,GwGs\\J!JIJ
J~pfoG q}9< eGiGwGw\\JJI J!J89<xu i Gw9<\. J 60. H -/M.^pl. _A[\rE=qs`{/g,a1.:>!tsmC0 t}cd lUp` 0
>:00?f-<9U<)C0u0E. @ 03)C6)p9<9p+ 0S . . 9E 0. 9E E-U-<.f> . 9E iGw\ J|.-/<013H|;C 9<- > 0k dB5-<6 C +j01E&.:0o)Cd-/>:. <e0 Gw\ J 9<Bd> @
ifGwG\9<J i,GsH \ JIzJ 0?zj 9<;{ -/ {9< -/ >:<eGsf\0?JX.7f. Gw-/i,.SGs\+ JI +KJ @C;9/d.S.* 9< 0e. Gw\0uJ69ECH+  . 9<f~G D . J-U .
. 9< -U . ."i Gw&\. 0J
0z-/-EHX+.z+ z .!. - 9f "9<;=C C0 -<6? 9<C6>:9E>!>!07C0A68+ . .1 . -U 9<.*G}z
9< 0 fe>:)=01Gs\- 9 J 9E01 +@pDC 9E. J >*0 . .0-U6?.:9<0?fC+ 0? X. . 9< e.:>!GsC\0<J* P{ HkC60
e9<CGw 6\G Jz i. Gw\-UfJI. JGei GwGw\\9<JJ!J @=G . J\i0? Gw>:\09EJ&-/ >:9<Gw0ki,> Gs-u\CJIJ-/.! 9E>>-/ KP{{ p60 ;=9<0?> .
" -/p C6 >:+01- -59E! 6G 9E C J\@d .9<-/HX.
ezGsk\ Jz0? D
9< eGs\J 9< G J 9E GiGw\J!J\ 9E GiGw\J!J 9< GiGw\JIJ
G + J3-/9<"p> + eGwi\GwJ&\Ju5fG}IGi CGw6?\ 09EJ!>J89E-< a1zbQi,`{GsC\g -/J.!BE<>-/H/zJ @{9ff;p9EG 01B/ >Ae/Gw\ JJ@xz. z 0?Cf G e9< Gw\ i,-<JjGs \ 0<JIJ B i,Gse\GwJ\J 9E >fB-<
Cf-/G .!B A>-//z J { z ;=0?0?K> f. 0?@ >:0 9 -<>!e0fGw\-Jp-U.!Cf>:-<GwQi,{Gs\JIJ ;p01
> 9U& 01-<<C01>1+K@ -j 6)9E)= 9 .:0~-/XB .S<u/ D
-/C 6 . -/. @dV  6 3B< z fB )=/9 :/I ; 0<1 B A/ ?B @ 0<@,B GsV{ B J U@ 9<>
G 0 J3eGw\P Jf GIGMeGw \JIJ eJ8Gwx\zJQf\G!G} e-/ Gs \0<JI J O J 0. ze Gw\J 9<>-/XC-U.:>:-<E{;p01>
 -/C)+K)=-39 60*9<. -U.-/. X.S5D C6 . -/ . 0?ue.Gw\Jk0?>:0
-/ >:G}0
e-Gs\pJI-UJ .!C >:-<C {/  @ ;= 0E0?> @
Gw:J33Ck-/ .!eGs> \ -/ J* { Uf@ ;=Gw9Ei,0?>*Gs> \-/JIJ8 "K-<aACb+K`{g-j @i,69EGs\ CJ
.:6 -/jX.kS*uG} efGw)=\9 DJ!J8:Ixu C;z6 0< .7 -U . .!>:eGs0E\ Jz 0?i>:0Gw\-<J
>!0 9<- >

i -/Gw \J SGM e5Gw\J!J .  DC z 0? iGw\J eGw\J 9E>k-/  @ 9
G J3eGwG}\eJGs BJIG}J e Gsz 0?B J!J8. xz z0?>:0*&-/>:0"-S-/C -U0<.: O >:-<0?.d{e ;p0;=-0?> GI-<H C+ +fJ -P 69E) )= .9 -/ X0 .e Gw\J D
G C6 . J -/.3 B eGw\J e Gs B J~ B < !! A G B @ 0<@ B
+dB 9E9<Z ."+KB -<01 01 +|9j. ;p 0 -U@ ."-39<.!6?9f>k9<E-/0 .:.
-<-fE.k69E E .:>: @-E+ D 68 . C6 9<6 \ J . f-/. )pe9 Gw\J;C 0E 4 eGw6 9EB J > @0;d. .k0?>:00


GspJeeGwGw\\JAJ/|dfG}eG}eGs\Gs\JIJIJJGMeG}eGw\Gs\J!J8JIJQxz .!>:Q0< .!Gs>:z0EC .:-/-E.!6801.A@U01. X0. .!>: 9<.!>:9<E0?E> 0? >.:-/;=.!010?6?f-<01E 0.
.-/ >:0u0?>:-0~:-/01>:>I0. C|9E>!. 0 -U .CC68. 9E >!9E0 -<p689U. &9<0A + ;=9E0?9<.  30.:9 0 . TW G}e-/CGw\+ J!J ! J+d0<P
C. ) )p-/9 . 0f @". -U0.
i|Gw\J&D fC6 GM eGw. \ J!-/J . i,zGs\01J3 . 01e>!0Gs\-<J7>!0k 9<-f>p-/-U .!C>:-<Z{ j;=&0?K> u -/-/C C+ -u6? 9< -< >!.:E-<0?X>A. @
 0A6 0 ! -/H >: <@Zz 0f01 ue-GwK\J
-/  93e- Gw!\ JQf0i,Gs. \ J*-/. i,eGs\Gw\JJ\ D e 9<Gw\>kJz-< eGw\J" 9<>-<d.
G B JKfGMLGwO N
9<PK \V J Hx T F @ JK 9 YZ. eCbQGw^{ \JZ)>:oaA9<b;icGw0?\a<3
J@,q}03G}Gwe\ JSGwp\= J!/J B @ ~G1w.  0B)C>!9{9 H <@ JQ <9E>!"0a1. bQ `{0 gHu Gw\JS. 0
>!u0A-/6 >: C>:0?fC-u6?0<$C 8 ."8@;p;0A6?-/. .
0 +d 9{. 0 Z- .*9U)&>:9U01<> 0ST 9<-/>{+dX01>. .! 01>!p3 z" .:>:-/.!0?E 47 01
-.!/{>:K ;p0- 9< d0u0?.0A +j. .!-/&9. +d6 9 . J 9X 9 9E0k<>01-5>!69E;C{- + < 0?05 6? 9<01>
C.6. 0E .!@\09~)C9E0u>!E9U-/E> 0u.  . I-/ <0f. . . 050 0 9<.:X-/; -/.! > 01. . .! d01X. . 9E;CG - -< f.0 0B9<. |9d W+ .
..!9|-/;p. 0E GwN \01Jkf 0? ;=0?9<>  |-5 9E.!>> 6 >!9E @Z.  9j0u.!0-U{.I.A.:@0?&> 0 9U.  ; j9 0f6 ;d .:9X>:-E9 68 .0 5-<C9U+ 0?> T
9<>-<+dX0?.>k.:.!9 0?>:  ;K.!>4-<68>.u+ -C-/> . . ) 0|09 79 .@C;-Ud.:.5>:-<03E  0*: -<6.!9<C-<+ ;p 0;d. .! >-/-<.6.505-/0?9<<01+
9U -/0?C> T +39<>6?+d9<0? > .:.!01-<>!E3. z: D 9< C>6 < .0 !-/. Gw\;=J0 . -UGs.
|. o 0?>:J 09<-< >!0k -u pz-U.!C0>:>:-<01\6{C>!>:0?C;=6?0?0>
>!&0107-/ . 9<=u.!+d>:9{0 Z .&01R <Fd0?Qfu-/9EE>:0+d01 >01 .:9 0 01 9< > C >!0
. R/-/V5.&G . 9< . 0 01> >! . TW0< @ -/ wp+ BUI +d0 HU 9E\?J 01@ >! 9p9 @
&03 z. 0?>:01X >!0|. -U. KR/V 9<C- @&&0 -E0. -U.
Gw\ J9U CGw3))po9 0J .9< -U . 9E> R -<CR +SF z0 C -"<0 )9<>:C9U>"<01;C
- . 006?>:- 0 0< . 9E> R F

  

9<. 60S. -U. R F  B H @ 9 






GIHAJ Gs J B G1w BU HU/JZ
B< G1w BU HUJ 9E GA B H<JZo
-U.*0S>!0A-/-<E.

GB J Gs J Gw oJ 9<
z9EKE.0-< > 010u -. !> 0 . .zTW . --< C0&+ > 9E >\ ! . +d. 0fTW 9 -/.!fC9
+ GI;=HA!0J +d.!>:09C0 9|QG fB J 9<@ . >: 0 0E0z. 6@ 9E-< B< .:. -/G1 Xw0u. 6 9<BU >! 9E.E-/HX.=. 9 k . J 0z>!9E9EE E.SGs -<9 > k. . J 0


 6?B -<CG 601C 6 C u. -/0<0 659E .f; 9E jE<701>1-/@


C+|-/.|>:0?)9<-<> 6 . J @ & 0 01BU07 .9E -U.. 0S . 0 d. 5TW 6-/0 C + .:!9 + 07-;{E 0
B-/;=Gs 9U< 0EB @<. HU E0 Jj. 0S X0S@ 6 0<9 @60 KzR/R/V V P{9Up6039/&. 03 6?0
-/ . 9K-U>:.A01@ XI C >!6?0A0 + KR R<V @
&G$HU0 B J$- <0 GIH EUHR CXGwJ R/G}V{R J
F UR XH Jp Gw z ?J @d-/;{p + GIHHAJ @ @ 9 BU  H
  






Gw J Gs oJ 9< GIG}R F /R XJ JZH pGw R/VXJ


Gw oJ?G 9< 9< G}R F UR XJH X J
 
 

.P{ C060k>!01 f - -U .* 0.:0?-<>:E . ";p0Gs 0? XJz-U . < 0EGs@ 0<o@&.J 9<-U. H X @p &0k-< >!09E>:01 -< GsR F -UR E J C z. -U.

 


.9{9E 9E0 -)=;p 01-<6 +j 63XH {. {Z 9<;p0 01>!> 01GsR {-/01>:U0?R ZF ;=JS.0?>zG -|f. 6)=-U9E9<. C>!+ .: -/ . X 9<9<.A @ 9EGs RFU6 R . E J+d-U9{ . 0 R9E{ U9< R .G}FR {{ UER 9<FH <J J0 zDC@ G
01@ C0?6>:900





Gw 0?X-/ J J@. 9E 0|>:0?u@C-- +d 0 I >:.:010?+>: -/>:0 C+d0101+0?X-U. <0|-/C+o0 -<0 Gw J|


 

G}REJKcGMLgQOh N
PjV B TWD VX JzcYZl ` []Qr<]^=^pg_A_1`a1caAg,baAcd_<aux Gw\mJ[_AqsgQGwj c dlUJ\`XrE[\lG lUd`{JZg rE` a?lUu`{`=bQ `ElU` gh|cg H   

mp`+d>^=-]Q[\ lt}qs r<cqsa g. _1$cC07g`X>:lh016?_1>:q}mno>!01C[]6_Ats0


`qsgQ5.! >:W0?[Q0<aAg@dbr<`a10Sq}_A^p [ g e_1 a1qw_AaA)^[\)=aA9 aAqs b^=0
cg. a n-U. `EGs\aAbJk^\h-/jx 0GMe-EGw\68.z J!J8 xC-/ZM. @"[Q ) _?aA0 qs01M9 m
 
"! $# &% ('
*) +)

;9 \d.Q! 1009/.:K 0.@ Q -/)C.\>!9/9E0?.7dE.-E0? >:68*.:.$C&-/9k9<63T C01>: 0?- +d) >:>:0?9dZ9d+d+d@{C066?9E 0S>!>:. .0 0)p09E.!>:C>:010?6+ 0EC @A>!6?>:70?9<.!C>:9 >!6?0 0S )=.!;>:9<0?)Cp0 >!+ 9E ;C01. .:9
S- 9 9EZC!d; 1.)0 >:9E9< ; 0?0? .1@


-/0A-<C-;p+ 019<01|+ 4 0fD 9 . u A0 Gw 0 )C@d>!Jp 9E 0< ;@ B01@E u G0?. B >: 0"0u . 9<z0 0u01>!9<9 0k T -<!>!01 10- 0 Gw{9dJ +d{07J -U-j.H0A0?-E0? 0?<01. Q z6?0u 9<39<>:>!.. 0 010S)=> 9<.!>:C 0?+ 0<- @
-, ., /
 
,  0 &,  1

.! 9kC;-S))>:9<>:9<;;C0?01 9-/>:07! 10A0 -<0 JP{ CG 6 07&. 0z 0.:>!9U<.!019> E0A9-<.:+ 9k 9E0?>"<01- )C>! 9E;Gw01 {J9 IH ?@0 . 0?u ;=u9/.
2
 3

2  52 1
42

Gw3 {J @{. 0k6?9 ."9 . 09E T 0A- C9{+0 z


2 
2 

< 8 Gw3 {J GIGs dJHAJQ < 8


76 98 76 98


:; 2    :;


GIGw dJHJQ G!Gw {JQHAJ?B GIGs dJ B J Gs J


< <
1 
1 

Gs 9/. 9/. Gw 60 d. J -U.7Bd. J 01z>!0f 0?-/>:>:070 -<G!>!Gw0 Gw{J{ J B 0AJ-< 0 D 5.H 0
.:Gw>!010< @{d9<JC07H -/..:0?0A>:-< 6 79 . . 070 0? <301 @
1 

z-<;p 01 01. + 0k.:9/.:-<H<\ 69 1.Gw9 d. J0 0AB3-<-/0 Cz+KS.$93Gw-/.d. J 0u0?EGw0?\J&-/;=d0?Gw 01+ J @ 9f. Gs 0 d6J&9 .9 H
1
2
3 3
1
1
2 

. 0*019UX. 0?>!E070?.!>A>:@z0?.0 z3 Gs\$J .~-GwE  0J\: dGwG K J0  E9<Gs >:01 +JSG . ;{ 0G$6?H?- = J!0KJ 0?>:0 9/. 

-)p59 !! ;. )C .$0f0?9 { )C 6 *.!<. @ 9< C -/ . . )= 9 E:!9/ ;.;p0 0& ~)p9 . !! 7;C!0E J)CO 00f.\6? - 0.:>!.:9 .!9* -/)CC>!9U+dE0k0.. -U-U..
=

Gw \ JD Gs C J6 @Z . . -/-U. . @,. -U.7. 0?>:Gw0\J-<>! 0- C -/ .! >9E-/> Q{;= 0? > G -/0~p+~6?-<6>!9E0  ."-/X9/. .
.!)9 >:9<6;9E 0? 05.:-U. .: 0?0jf0?6?X9<. J.:-<P{E p. 60 . 0 > 01 >!. 0|TW -<C . + I. +d 0 0|6 9E 0? E.:0?-/>QXD.f@u&0&9d6? 6CE>!> .!>:C  . H 0
9<. 60k. -U.. 0>!0A6>:>:0?C6?07>:0?-U. 9Eu-/<0 * 0? 0k9<C 9<> @ 95 8 0k
>

-<03.:9 -/p+d03. 0.:0?>: 5 0?)p-/>-U.!01E E -<C+




8
01 >!E 0 01- >! E. 0S -0 ;C9E-  0> 61I- ;p@1-0. 0k 0?kf6?- 9E >!0 0C . G}-/z Gs \J)01>: 6?010 6 : !-< 9E>! 9<-/S> ;=. K9< d0 .
9< Cdz. 6 ~9<0S .:90 -/ 7.!- 0? f .-U9E01.:E0?. f01 &0? 9EX>!.
? @6
3  6
@6 A 
3 3 6
B C

9<9<>S0 -<9E>*6)9E>:9<;)C0?0?3.!0?@C0: 0 J : )p0A6 6?-<9/. 0?>: 0 .-U.!0A+0 C6C+d0 . 0?>:0


D

 -<X .Z9U.! 9* )C zC>!9U)01E)p0 9 . 0SGw.9< > -UJ&~.*0 Gs Q-E077)Cd9<>!J{9Uj>E0?6| G 9 {. J{600 9 .: -/;C.!- 0? f0016?E- Gs. 0E @19<>*0-/{uJ -j G )Cd )pJ{@=9 -/ C0 +j. -U 0.
E

G B J G G dJIJ W. .!01f)d. K -/..  )=9 E..!9 -



 G
F
G
 / G
H

. 0?-/E. . ;00<.: 0?>: u G =UB J$ N 01fG 0?? ;=0?>


. G -/d.JIJ -/0 >:0 - 9U 0?~> T 69E>:- +:0?>*. .:0?-U>:.
. @ 01C p6+ 0
 G G

9Gs ->: 01J- 9<Gs\ Jp @d-/B))C-<Gs>!01 XB .!J)=0?> 01- 68.:|9<>!d0A.- 9<9< C-<;Gs\0<@J6?-<3;pGs0k\ J @ 0A +.: 96 I)>:059U<{0 k9U. -U.
FIKJML NL PORQ
SB C

X.!z>: 0< 0j .5&9E>!- .I.!0 -<>:+d01>1 9U>:0?f01;=0?>f. -U. @ 9


>!0A?-/ z-/X . zGw 01>!J0 9<>:0< @ Gw zJ  .: >!C0 G G J J$ G dJ G3d J -/D~.9E>10 @
 T U V G


>.!0A-/0>:>>:-<  . TW p-/@ p+ ! +0 { <9EE 0 8 . * 0*U9U-<> 0? -/E;0?>A0 @d. C 69<9fp<+ 0 ..* 9E> + 9 . 9/ .0k47+df0?)=@C0?;=p01+d6?0?-<C 6? 0<0 @
A G
W6

$>! 0AX .7 >:9<0?f.!001.E .A-/@. -/C +j 9E 07@ . 9-/.


.A+d 9{0 0? CZ9< . { <.!9<9|<>!0 0A E J >: 0 G - .:>!9E<01>
6 X6

 @6

-<6.!KC-<0|-f .7 .!-<.!0 9 !!f 9U)0?>A.  -/. 0 Gs- E 07J. -/ . Gw z J& )C>!Gs9{ 9 9{d9<J\
! G d JZ-<>1 @p; d.
6 6

= Gw I G {dJuJ DC@QG d05Ju - K +>! 9E) -/  . 0 G 0u .! 01>!B -<J C+o69E GC61C +d05. -/G d. JIJ Gw P{ JuC6 0
( G  G
E 
G

G B G J$ B DC J$@ 0Ez@ -/ .
B &0 >:01 -<D5 zN -/0A-/X>:. >:-<* Gs C @<J"& 0 0? 0* . -/z.  .* 01.!>:9<0
 

.!9u >:I01 X01 + >!0. -U.


P{ p60S. C 6?9<C+ . 9Ej+d9{0 Z .
+d01)p01C+j9< @d0-/>:0

 

GsVXJKGMLON
P3V/T F J b` "Bq 5^=cgQgQch r<rEq" g[ n D `XlU_ _1HEcdx aAqs_A|Mm` aAbg``lUaA`XbrE`[\l=lU`{`{gg`XrE`lUcda1q}g
6 ; ;

; ; ZY [ \)
) ] E]

W[G gQJ r/aAY\qsb^=^{g a1bQcdm a 33G {G {JJ" 7 3G {xJ\ jG XJx 7


;
] ^] 2 _; ] ; ] a` "
8 8

- . 0.$9 01> 0 -/p+ ! 9U . -U.z. 0 > . 0?.!. 0?>: 0?I.Iu. -Up.6 @p "> ) . C5 9<d9/..
Abc) $b Gd fefg ] d
<
Fb Gd hd Vdb Gd $d b d

dp50 6 |6 -0? <X-<0 .1>:*+0?>A -U. 0?0A+d01+ -/~-/<01;>- 6S)>!9{9

6.!C-<<@=. C 9/.
 B 4C

;@j ;@j ; ;

jG XJ E jG XJ
:;
g
;
:;
g
;

:;
g
;
:;
g
;


d idb d id 3b d 0d ] d ] d (d ] d ] d
8 8

;{ f. >! 010 ) -E0A6 6 9<pk+ . 0SU-/;{> -<; 0 Bd O . 0? .10 9{> 9<. | -U.z. ;{0 oT .!0?H >:@d -/C"+5 01. )C -/0S>-UU.:-/0?> <-/Q;K0 0
< < < <
k2  U2 l2

<0?. U2 d

3G {J 3G {JGIH& J { G J :;
g
; ;


d idb Gd md b Gd m] nd G] i] nd
8 8 8

N. C01 ;=01016?;=9<0?f> 0 C |. -U.  D@ H -/p+ 9E> Bd@


< ; ; ;
] ] ] o] (] p2
8 8

jG XJ jG XJ
;


;
g
:;


d idb d id b d 0] d i] d ] d

;d.".  - ."0?{)C>!0 !! 9E $ . jG XJ @- +d0 I >:01+


<
j

G ; J~Y\b^{a1bQcda 3G {JS *ubQ`ElU` Cc gh


b d
b Gd Vx q  zx y

xzP{ C60 3G {J 3G {J< 3G {J @<0 -<0 GIHZ 


8 q  b Gd
q s
 r K
8 tu
(d Fdb Gd /d
8kvt uMw
b Gd Ud Ud J jG XJ @b d 0d


0E@ 3G {J : &4j. 09<. 01> -/C+Z@


b Gd u

H H H G!G$H" G {JIJQG$H* QG {JIJIJ: F G ,J d F 8{u8Ku

F H" H" G$H* XJ?G$H" XJ H"G f ,J


x y Gd Sx Gd x x y d
l| Sx4d x{y d+} Sx{d x{y d x x y d $x xKy d

P01{X CC6-<0 }@,- +d0 ! >!0A +Fd @ G <01 0?>-/H M@C-/C9E+ 09<C+ H @{-.< 0S0 .! 9 0S.$-<69u.!9<0> d)H*>: 0 :! 9E -/>: 0
x xy x xy x xy

)=kC0?G 6> 9< >:.  -U. -| J?)CG -<f>I. -< > -<J 6. 9<. -U .+d016? 9<@ fH)= 9 J ! . 9E .!9 kC+KG 6 9<  .J?-/G X. ,J -<C+ -<C+
md md
Gd $x 8 Gd ~x y 8 k Vd $d Gd x y Gd (x k


G 6 JY\b^{ a1bQcd a jG XJ G J x 0 -E0K. -U.


u ; ; ;
8{u8Ku u8Kt ;X u8kt v X
; b d x ;

G {J -<C+ G {J G - 6?-<;p0K<0?> 01+9 . ) T


e*g x y d

01~69E;=C 9/+|. 01XCI -U+d. 0 9E 9 J . z 0 01>!0 > 9<.>:0<0AE@ p -U. 9<o;{ H @-/C+ I -/>: 9<>. 0
; < ; q  8Ktu
e g
* x{d efg xKy d D
< 8ktv u <
 Vx{d

jG XJ H F H" H H" H H F G J


; ; ;
g


b d :; x x y nd
| Ex{d x4y ds}

- 
+ 0 !
:
> 1
0 
+
G + J3ySlU^{vp`faAbcdaEZW^Cl D F ,l^=[QghQ`{haA^|aAb`fgQ`{cdlU`X_1aSqsg,a1`{=`XlX,qs_ ;
;
;
<

x & GwV 6 J @ G J 9<> D Gw -<6. 9<> D J P{ C607F 2@


; ; 2 x
] ] x xy ;

F D@ 9 2 R @ 9 G J 0 : . H -< z - - >:9< Z P{ p 60 @


R2 =2
q 
; x y; ;8 q  / x y ~ x
y ; q  8 q 
;

-/ 95-/ E.:0?E0?>A@d.  0A-/ . -/. . . 0k01-<>!0 . X.!01<0?>


.!9 G
2 ] x xy x ; ]
q  q 

-<9<6..1@{.$9f0  01--<E>!0 0 ! . 9U "X.!u0?E. 0? > -U .z J . 01>!0 9f-/; < .$,<. -U. @{. -U.. 01>!07-/>:0
x
q 
;

G 0 JjySlU^{vp`a1bQcda W^Cl D x  GwV + J @


; ;
;@j ;@j
U] (x j ] f; x t vt vt

P{ C60 E @d0 -E0*. -U. G , ,J dH z @{ ! C


2
r q  r t w q  w
q  8 q; 

GwV 6 J -/X- Z@ @C- +d0 ! >!0A+


7x
y *x ; ; Mx y x
;Dj

G F JK^pGMLO_1N
q <Pf`oV RUT _1B cJ a1kqs_ bQ`5`X_jlU [QgGs\gQJ7qsgQ aAqsnGs` B JQGs\Jz ^p "cCugbQc`Xts=l`{^pcl_~qsa1bQa1bQn `olU[^=gQgogq}cggq}g\aAqs]n[`a
] Vx t 8 tv 0x ] 0x
r q  w
Y

X GwGw\J3UVX^=Jcg cCWts^p=l^ClU_Aqw^paAbnn `or<^= g^p_1a1gcg,ca g=qsx g]Q[aobQcd^pa|q}_1_q <a1`bQ`t}_AcdcdlUa1pq}`{_ _1a~`{_qsg, a1`{ =Gs\`XJ|l
 
 3

_1B [Qrb9<a1bQ cdVa q}9<_ c_1 mZ@ no 9 ]Qa1 ^p a1q}r<ct}ftwmGw Wc_?aA`XljaAJub cC9<g> 9E0 P{ C60 V D Gs )p@,0A6 0 6? -<-E<0 @

/
 V
P


9E9E> Gw\ J B @J . z01>! 0j -/ @d>:05;{u. . >! 010 0~)=9- : I.:0?; > z . 0 01 9<>:0?B 3@ 9<Gw\ J@B Gw 9< J 9<>uBo
h    84  D
  

<9E> -/U-< P{0 C 690z 0 -<C>!6 0 E. .:0?-/>:.0 B .!0A+ 9< - -/C-<+ >!E0C- >: )p 9 !- ! ;CXf0E@ )d.: 9/. . 610?-/>:0 -<>! 0z- -/.!{0? >. X .!-<0 T
H
 

H

H


Gw 0E@ Gw\J dGsGw\J!JIJ @. 010C0?01+K9<.S6?9< ! +0?>. 0f9/. 0?>.$9j61- 0



H


9Ef -<0 68.A/@  B D@ 9 9E Gw\@ JS 0<@ H kGw V J V z S Gs\@{. J7 01 d Gs Gw\J!fJSGs dGs J&J7 9<>

   7 6 0  7 684

-/C+j9E 9E 9< @ 0<@ -/p+|9E



F
H
  6
  

V V G B J G B J V 2

H
  6         

z @ 9. & 0?0>:0z0?-<0A>!+0 X9/.!0?.fE60?9<> I +d 0?>kH .S 05p6)= 9 :. ! -U; . .$Kd>:.  -/ .f- B { f)d9<.!9<. 6?-/9E> B - .!01>9E. -<

 

 
H H


z \0>!6? 9< f- ) dX.f-U.)d .:9E9/. -/61;=-/9U< 0 !- .:9U0? >z . . -/-U .&. 0 f-<>!E0 V . C W ! <U-/0*9 f C6 . -U. .L 1 1 +

G EJKpGML^\N*^ZhOQPcV/gQT hEJ_1Y\^=[n]]` ^=_Ac`h&^=


gQc`gQbQh c_Scc5hr<`X^=vZtsq}t}r<`{`r/a1uq}^pbQgKqsr^pbQ~crErEr<^p`Xno]Qa1]_[a1c`Xl]crAbQqwlqw]^=_Ek=r_Ab^pnqs]Q`_



- "

cqsggQhKa1bQ[Q`j_1`{a1`_"`{a<cx rbK?a1z^5a:aA`{^_?a"=aA^Zb^Z`h^CrAaAbQbqw`X]l{_x a1`{_1an^=^pgl`j`kcvZgQqw^CvZaAqshKb`Xhl{`{Q_A`{r/clUrqw]Qba1q}qs^p_glU`Xqs_*]^C=lqwv=aA`X`Xgh


E)
#n

Qp^CaA^\cCb^Zh `Xh*lcrgQq}bQhqwc]c pp^Z^Zc^\^\hhhrrb^pblqsqs]]lUcaA`Xh`Xa1_1x [a1lU_Kgc _3cclhcCgrhQbQ^pqw]n ScCa1bQg` _1`Xclhurbb`{qs]ga1q}_~`{_1lUa1`XqsgQ]^ClcCaAg,`Xhm


"! %
= () i)
) = m)

G - JgQY\b^Ca^{ _A[aAbr<cdqsaE`{jg,a~q}aAn^^pq}hl``{g,aAa1bq}McmgubQ qsB rbrbQrAqwbQ]qw_]_cdlUc` l` QcCchh&|xa1bQ qs9/_.:0uh`X. vZ-/q}.r<`-/{qs _


)
^)

.! 0 .">: 60 < 0A+. ;{@d>!0 -3 69E. 01 6. >:9<9< 9 -<X-/| T 6;C9<-E+K; 6 C-U ) . 9E |z9 6  &) 0u @616-/9<C+9<. X-CE9U0 ;=0? 019< >
V)

;C -E0>!+07!6.  9U -U) ." -< 0kG}9*z+d. 9 0?-U>:=.0U-<0>! 0 -61<-/ 9E0-/9<0k.Q.!;CC0 -<01 +36.0 >:6!0 -/ ) > . S {. -/9U.7 9E > +d0 >:0 . . -U<.0? 0 C-+ E 610-U-<.!0
;C C-E6?+6?06 :I ) < 01E@= 9< > 0?0+-<>:0 )C 0E@. . f0& .:0 . f ~ 9| . 0f ;=@/0 )= 0?.> &9<0u>:6?-<0A+
s
3 3


+d-f9 69E C6.:9 !! 9E9UZ J . -U.z. 0S.!0 .">:0 . ;=0 C6 . -U."&0S6?-<9<."+>:-


Pp
3 3
L J
p 

G ; J qs^pngQ_A^pqslhQ``El3aAbaAcCbg`o]Q lUB ^ ^=tsk`{n aAb`^= rAbQqwg]hQ_qsgQcl`^pgQp^\`o^Zph^\"^ZaAhb`{rgbQqw]wxo BUY\ bQ^{]cqslAa1ubQcdq}_1a<`


 ) p

a1^=`{g_1`a1_^=[k_AgQqsgQ`{cdlUa1twmbQ`3bhc`Xt}vZq}a1r<bQ`3`cd_AlUq `3E`=_1x|[O -<r<;pq}`X01g,a. a10f^K6 lC`{ ) hQ [rE`j@ a1bQ`|H<]Q lU^ Its`{n fKa1^ 0 ; )

-/>:>)-)= 9 0C0 6 -. E 0-U. -/ -<H E9< > . . 0 >:0 . GG {9<J > J 6 9 >: 0.:I >: u-~.:.$9&9.!0 T 01 .fE.: >! @
G
p 2 9
s2
3 3
;

.$.-/ p-U95+ .
6 .  B 0?) ,3 @C -/. >:. 0 010-<>:. 0 < 0 9{9d .*-<+689 @ .
95. I-/.
05f6? -<9<~>:.:09f) . .!6 0 -< .
G} --/&J . 9 . 0 . 0? >:0?> 0k.-/>:9E-/0S>:00<9u<9{4
f9d. 9<+j >:0?07>: . 0A -/-< 0< @
3 ;  

-/p0+69E+ !6? -<+d>:01+ >" 6 79{. 9 !0? )C- 0 > : 9 01 -E66  )>!01 )p@X9E.:0>I. . . 0*. 9< . 01 01> -/E - < 9{9d .+9< z0S-/ 9<0A. - <010 >1 @


- - Eu0
-/. 010k>-/) < 9E0> 9 . 6 G 7 ) J @= C 6 &0.!0 .S>!0A6> I <01EK9/. 0?>S9<>+ @=0
E H fzC +0 0| f)d9E.>!07-<>!<>9{-9d +|6 C ) .Q. ;= 0-<|9<;C -ET +0?f )d.$E@U-/C+ . 01E.:> 0 .
Zssk G

RVB qs`{ ghQ0?CqslU /`X. a1 [lg  B H


s .
i

 F W^Cl 0?H <. .: 9 0?G <. B s H BUM B wJ


i,~
P
+ -
+ -

2H D qs B f H B
p3 
3  
 G 
,~,

H<H BH `{ghQqs B
1

H1R`{ghQW^Cl


, {H?H VF jqs B B B9{ +C+


,


,
HH,~,
H
 HH 2 `{W^Cgl hQqs H .:9 0?<. s BU
K

B/B DH qs B H  H
P
=
+ -

B<B RB `{ghQqs B ,~,


1

BB<VF`{6>:g01hQ-/.!W^C0Sl -/>:>:- H
V BB lU`E aA[\lUg

5+s G ,
3 
,
G J G J
-/,0 6  .: -/) >! .k z.  0 )qs >:9{.!0 6? 01.+d9<C5>!05 C0 . H F  )Cd. 0?IdH<)p 0A68.!0AI+5 ;@f. 01f-< )p 9E>I~.-/. X . -U.G 69< . I.:0 +d 0?. >
Z+k 

3 3
+

>:-/p+ . 0. -  . -/;C<-E9E+> @/.  . 9<9E|d. . . >:J 0? 0k6  ) @d9 G k 6 J. 0 -/> -< .zE9<.$&> 9u. -<>!07 <9{ 9d6 + 

>:50.! CG >! +d-"0 I 0?>:01o+-<@ >! .


>-u
-69EX;=.:0- f )">!9U. E001+ .!9501X>:.!01> -E 0 +j 9<9  5 . 0k 6 0? X-<.:>>!00 C 9/9 . u-<>!E 01. +
R5s+N
R,
 ,
&

9dz+ + 0 07C-/+ >: 0*60 . @ 0 ! CC+6?0 60 . 09 0?. X .:07> 60 C ) . 0? 6 < 01 0 p + - 6?<0 0 -/9/>:.z0~<0?-/.z
+ u 6?-/-/>:<>+d0A+0A+W .J
V

; d01.*-  0S.:9<9 01."0z. . 0k-/.+d0?. .:- 61-/f;=0*+d9<0 f. f0 Gw\J @< 01>!0 ~ 0?C/. @ s .

0-69{- 9< ) . { U-/-/. > -<~X. 9<>: 9<0S>. . -<0 W ^p-/l 99{ 9<). 9<06  C) 0 9/K.7fC+-<0?>!01E+Z01+ @&0j-<-/>!>:005< 9{ 9d<+01
/B &C

.. f-U.0 .C6>: 0?.!f>:0?07X.:01)=+9<@E . 01 . 0 -/ . 0?-U> . 9EZ3 >:. 0 .:0 >: .:-/01.!+ 01f01X .z-/- C +f.!>:C906 . -<0S<- 0 . 

9 0?.>:00u6 -<+d ) 0E@Z9<.!0> .:01+61o-/3>:0;p.:0>!EC9{01+9{+Z 9Ez 0?.  . j0k0?{ 0E;=K0?>


. 9  6?- u 0E-/@>:<0A9/+j.6 ;=C9/ .)

p3
Zp  

;{+d! 0Af6-U>:)01.S-f 9<019 +~; . ;X0?>:H < 0zBz@. C-U7. 0. .. & 0f0. {fp- .! >:X;p.:0
010?>7C. -<9 C-/ .60 fCf9<.:>:0?-<0")Z>!E@Z. 01-<+-/C +E@9{ 9{-U-/.7+K .!96 01 >! . ) 07C+d-U6 01.C6? 9E>!) Z0A - @ 019/+ 0.
uP -/)C>:)p<90A+ 0|. -/-/>:.107@<-/9{.9d+  0 H Fd@0?-<68.: i 9 . 036  ) p+d0d01+;{. 0j T
F

u C-/+d>:0<d0A0A+|+K01;{X.!> . 0 059 C u-/H >:<01+B 01E .:B> 0 -/9 >:0k<9{H9d+@=-/B Cw+ 0?B -<68-/.:>: 0f ;C-<9 + . Gs0 6 9/C. )60
=
3 3

. G +0-U."&0A0S+j-/9<>:j0 E0 9<>H? V{CJ -/. C + 0S- ."0?X.:>! ZQ 9d++ Jz 0? i" j .


K
3 

,

G9Es>Gw-/J|J{ii ;p 0?@ 9<.$K&> 010? 9d+H +3-<C-/+C+w. BU0kE6 @ C ) CB Q+d05dH0A+| ;{ Cf-<>!E01 +E@9X. 9d +0?. 0z6 C )


.. C +d00 0W d^p. 0A l + T 9{;{9E)u9<-/B >:< 0A+u0 H 0?H X-<2 .:C> + 0- 9 B !-/H >:0A0&+@/;=09/B . w-E 68E .!BU9X 9diC+-/ 9<>:B">0
9 ;p< 9<9{. . 9d +0z;C@d6 -/-ECp+ ) + Qz0? dC -E+d 680? .:{@/0A + ?;{01 B
K 3


+

9-/>:0j. ;C0-<+6  ) 9< >:p0?+d9U0Ed0?01>A+@ I;{ Co603. .0 0 . W^C T l C9{u9E-/)>:<u01+-/>:0? X .!> 9< 0 09 9 . 0H >!01uB - BC
f

3 


3 3

-/>:0 u-<>!E01+~ 01XB.!> 0 ;C-<+ B -U.k 0A-<6  B .:0?>-U. u 9E-/Z>:@\<- 0A +5.:0?0?> X.: . > 0 - >:0?6u9<f- )0.:C01 +Kz. 010? >:0
GSs.Gw J|J0ii-U .IBkB .:0? >Q6???- BkBd0<@ 9E@UK-z> .: 9/.9d-/+<+39 Z-/GCiC+| B . J8 u0kH 6 6  ) ) ZC+d C0?+d{0?0A{+j0A+S;X ;{7C \u -/>:<<9{019d+7+01 E.:> 0
, , ,  o

99 -/-<>:>!00<;C9{-E9d++@1 P{ C0?6?>:010 - Gw i-z B.!9<J.:-<<Hf9 C? G}Bz16 B J ) Z HC+d 0?{10A +Bd;{@,C0  u. -/ >:< 01-+7<001Ef.:> 9< 0>:0
&

iC<P 9{9dB)C+)p 9 6 GM0 ? ) iB JZB. -/H G};p?-<B+J3 oH . z0 9E0?>!f 0?> 6?B- 0< @Q0 3. 0?>B iC B Gwi B GMJ?B JG}? B H Ju9< >

6B CGM+d? ) 0QdB J0A p+ +d;{0Hjdo01+ ;{9duk++-/>:@ <u 0A9 +o-/>:0?<X0A .:+>* 0?0 X .:>f9 0 -< >!E9 01 -<+ >!0|5-<<>! 9{09d;Cz+-E @+ P{ -~01C>!.:6?0A9/0- . iC-/ "-~B9 .: 9/.:i?-< zBB9 @U679<CC? )6?B0
, ,
K $

.0?-/XX-U.:- >. 0 i  Bj09 -EG}0?-< f>!B 0JQ9EE>!0"9X9dEH +9X 9d@z+f 6 0?01 >!) 0A-U - .. 0A-U-/- .uu . f;CiC-E9 + B|. P6G}1 )) B )=7J9 p0<+d@EH 09<df6 01+K. ) ;{0*u9/ C.  +d0?0u>d0A-/+>:-<<C;{0A++ @
{

<9{9du+j-<>!6 E01 ) +~ 01. X .!-<> j 0 ;p-<9 + -<>!0f;C-E+ z S K.  61- 0.:9X930 -<0f9<>:0


P

-/d)C. -< >I0*. 0?6?X.:> -/ >0 Gs9 C0dC)p+d0A680?.:0A01++ @ J 6&9<0 0A-<E+fC0?uC6?-/0 >:<0A +. -<-/d.
. & 0*0 01 E-.:<> 0 0 ,9U u@E-<.>!E0101+
00-E-E6868.!.!5DD9 9 . . 00j6 6C ) ) & C p+d+d0?d0d01+|01+;Xu;XCuCf-/>:-<<>!01E+01+0?X01.!E> .:0 > 0 9 9 -<>!07-/>:<059{9d;C+-<+Z-<@C+-

s

.6z9E 0X .!>-/-<. .I+.!01068>1.>: 019E6?u> 9 ! <. 0 06?-< -E<68.!.9 . -U.. 0?>:0 ! 9<+uS;=09Ef 9E >!0&0*B 9 .-< 61060? )9<. >: f- 0?Z> . )-<d .
l

C
; -k-EC+9<9ET0?0 f @d)d .$5 -<6 >!j>- )f>:9E016>!0 0?9 u . 9 0 001E0?X-/.!> 0 )d .Ap +d05E9X9d+56 C ) . -/ C+0
kZ+k

G 6 J ^=m3a1`{_A`X_1a1a?aA_SqslUgQ` u[\[]qsl`{ch&ghK\_A_1b^=^{twvZq}gaAubccfa<lU\`{q}r<[nllU^p`XlgQ`5r<a1`fbQhQcgo`{_1r<l qB Q^=q}g5a1bQa1`bQ`rbQgqw[Q]n _kcdlU`X`l


 G) )

a1=`{^Z9<_1^Z> a1 h&_E. TxX61aAL- b 9E0&`{ g>:! aA+db01 >"` . p ^\0. ^Z -/h3<0


rA9EbQ9<> 5qw .] -/_* rEcg )Cd.&`k9 q}h!`{ ?g,0 aAq ;{`Xh33uGw9 qs\a1bKJ G z; GsJ \ 01J\ ]0?.cqs9<lA .!u010 - q} _1 . `
M
) \
~Zssk  .

.!9 0?07. -U.


Gs\J u-U, G J uHE  B &eGw\J8
! C 6?0107>!0 -<e,Gw\0Jf{9U Gw\ J . -U.03. 6?0S-/C>:0169/C. > ! -EK0. 61 -/-/ . Gw\JfG w B Ju.:e-<Gs<\0 J @
  M
 3


-/-/)C)  6?)-<d;.
0 9 Q !01 >!10E0 =G <f01 ! & .S  0?>:0f -/B )E) z 6? -/0;Cu0E@- & .:00?>z&. 9E 0?9<+ >:0? -E0 .:. 9| E 0?>9/ .
J i 
+sk

.P{ C-U6. 0|e. GwC\Jf-/. + u016?+. . 0.:9o69E+dC9K+ . 9<. 9<d{.5eGs{/9U Jj  0?eGs-<\68.:Jo 9<> 9E-Uf. 0 9<>: . H 0

G


-/pC+6.  9<p +d0?e> T 0 .: -/. E u0 -/@ . .3  9< + . ;=0K- 0A{- f! )d01>5.!9<.!. 9 6?-/+d9 9E +>j0?X . 6?p-<-/0 .! > . 6f-/.!9 0 9UJ E0?> T
.)C -<-U>I.. 6?eGs\-<>1J@p . 0? >:0-< 9<>!>0-C-/.!> -/Q{u;=0?-/>   -/3C+-/-|>:<6?0? 9<>A @ .: -<E.S0A6f0 ! -/D>:<@zC6 0
uP{ GsC-\6J070? R  >:~H 05@E .. 9< >*0-U-<. .: e-U .:Gw\0? fJ0? X. .! >:9E>0 -< 9E > ~-<C+H 9U C)o)p9 0*03. 6-/- . . -UH. 

-/p+3&0 -<0k)C>!9UE0?j. 0 .-U.:0?f0?X. 9E>-< z 01 B i


/- p+ w B G B URXJ @ 9

Gw J u-U, G J uH< B &eGs J


u-U= R fH< w B &
  M 
 3

R w B B/ R
" "
3 

3z Gs\ J*uSGw Gs\JGs\ J J -/fC3Gw+ \. JHE Gw0f P{fB CJ&- 6 .:0K0?>G$-/H . 9 B 01J$9< >:@EGs0?\ J0 G  - <. S0 G}.e Gs-/\ . JIJH Gs-<\CJ+SGsk\J @*Gs\BJ J 0&@ 4I CC-E6?6?000



9/. 0* {0?>*9U6 C )3- -I E<9X0*9dE+|9X9<9d>"+u;C6 -E+ )Z @Xz& 00k6?-/-/u<9E > .0 ..:9+d0 . <0? +0?X. f0?<01>!

 


HBKi D
Zssk Gw\J
RVW^Cl H .:9 G {J G $H< I !J

i2Z+k  +
3 
P

F qs B = f6 B )j . .: 9f0*.!>!0 0 .


C6 .9 )3 I S. 0*{9U" T <9{9d+
p3 2
(T ;

`{ghQqsi iSH


2

H +d0?X2D . lU`{0 `Eg aAhQ[\. WlU^Cg0 l Gw C+ 60 G 9 k I.id J 0 J <9{9d+6  )


0?>:0<@


-/<9E6 > . -<>!07u -/>: 6< 0A+ >!0?.!>: ;=-0 C9E0?>!0E@d&-/>:07>:-9< 6.z9<.X .0k- +d 0? C.:- . 0 P{ i C6?0?0SG Xk..!> I id0S0 J 99< > -<. T
5+ G
D =&+ 
p

6?- 0! >!01+C C~. f09 .  -<E9<> . Gw\JGw\JfGw\J @&0|-/>:0




Math 416 Homework 3 Solutions
Last updated 9 October 2005

(1) (CRLS 5.3-2) Consider the following algorithm:


Permute-without-Identity(A)
1 n length[A]
2 for i = 1 to n 1
3 swap A[i] and A[Random(i + 1, n)]
4 endfor
Does this code produce, at random, any permutation other than
the identity permutation? That is, does it produce a uniform
random non-identity permutation? It is easy to see that, as long as
length[A] > 1, the first entry of the output array is not the same as the
first entry of A, so the output is a non-identity permutation of the input.
(We assume tacitly, as usual, that the entries of A are distinct.) Note that
any choice of random numbers in this algorithm produces the same output
as if those same random numbers were chosen in the algorithm Permute-
in-Place. In particular, each possible output occurs for exactly one of the
possible choices of random numbers. That is, each possible output occurs
with the same probability.
Thus the only question is whether every non-identity output occurs. For
n = 2, the only non-identity permutation of A is hA[2], A[1]i, and this per-
mutation does occur. However, for n > 1, hA[1], . . . , A[n2], A[n], A[n1]i
is a non-identity permutation which cannot occur as the output of this al-
gorithm (since the algorithm always swaps the first entry of A with another
entry, and can never thereafter swap the first entry back into place). Thus,
for n = 1 or n > 2, this algorithm does not produce a uniform random
non-identity permutation.
(2) (CRLS 5.3-3) Consider the following algorithm:
Permute-with-All(A)
1 n length[A]
2 for i = 1 to n
3 swap A[i] and A[Random(1, n)]
4 endfor
Does this code produce a uniform random permutation? Why or
why not? Notice that there are nn choices of random numbers that could
be made (for each value of i from 1 to n, we have n choices), whereas there
are n! possible outputs. For n = 1 or 2, one can verify that nn = n n!, and
each of the n! possible outputs occurs n times. Thus, in this case, the code
produces a uniform random permutation of the output.
Now suppose that n > 2. If this code produces a uniform random permu-
tation, then each of the n! possible outputs should appear the same number
of times, say c times, so nn = cn!. Now n 1 divides the right-hand side,
so it should also divide the left-hand side. However, we actually have that
nn = (nn1 1)(n 1) + 1, so the remainder of nn upon division by n 1
is 1, not 0. (The reader is invited to see why this same method of proof
doesnt work for n = 1 or 2.)
1
2

(3) (CRLS C.1-11) Show that, for any n, j, k 0 with j + k n,


    
n n nj
.
j+k j k
Give both an algebraic proof and an argument interpreting as


counting the number of ways of choosing a collection of objects.


Give an example of n, j, k for which equality  doesn!not hold. We
n
 n! n nj
 (nj)!
have that j+k = (j+k)!(njk)! , whereas j k = j!(nj)! k!(njk)! =
n!
j!k!(njk)! . Since all the numbers involved are positive, we have that
n n nj
if and only if j!k! (j + k)!, or, equivalently, k! (j+k)!
  
j+k j k j! .
Since 1 j + 1, 2 j + 2, . . . k j + k, we have that
(j + k)!
k! = (1)(2) . . . (k) (j + 1)(j + 2) . . . (j + k) = .
j!
(4) (CRLS C.2-9) Suppose that you are a contestant in a game show
in which a prize is hidden behind one of three curtains. You will
win the prize if you select the correct curtain. After you have
picked one curtain but before the curtain is lifted, the host of the
show lifts one of the other curtains, revealing that the prize is
not behind it, and asks if you would like to switch your choice
to the third curtain. How would your chances of winning change
if you switched? This is a famous problem in probability, called the
Monty Hall problem, and has been the subject of much controversy (see
http://en.wikipedia.org/wiki/Monty_hall_problem for a history, as
well as a detailed discussion of the sometimes-unstated assumptions which
go into this problem).
The correct answer is that the probability of winning by remaining with
the original curtain is 1/3, whereas the probability of winning by switching
is (therefore) 2/3. A simple proof comes from comparing possibilities: If
the three curtains in question are labelled A, B and C, then the twelve
possible outcomes are as follows:
(a) The prize is behind curtain A.
(i) We picked A and the host opened B. We win by remaining with
the original curtain.
(ii) We picked A and the host opened C. We win by remaining with
the original curtain.
(iii) We picked B and the host opened C. We win by switching.
(iv) We picked C and the host opened B. We win by switching.
(b) The prize is behind curtain B.
(i) We picked B and the host opened A. We win by remaining with
the original curtain.
(ii) We picked B and the host opened C. We win by remaining with
the original curtain.
(iii) We picked A and the host opened C. We win by switching.
(iv) We picked C and the host opened A. We win by switching.
(c) The prize is behind curtain C.
(i) We picked C and the host opened A. We win by remaining with
the original curtain.
3

(ii) We picked C and the host opened B. We win by remaining with


the original curtain.
(iii) We picked A and the host opened B. We win by switching.
(iv) We picked B and the host opened A. We win by switching.
Upon counting, one sees that, in six of the twelve possible outcomes, we win
by remaining with the original curtain. Thus it seems that the probability
6
of winning with this strategy is 12 = 21 . However, this is not correct!
If we have picked the curtain hiding the prize, the host has to make a
decision about which of the remaining curtains he will open; one unstated
assumption is that he does so uniformly randomly. Thus the first two
events in each of the three sub-lists above have half the probability of the
remaining two, so our probability calculation changes a little. We see that
the probability of winning by remaining with the original curtain is in fact
(1/2 + 1/2) + (1/2 + 1/2) + (1/2 + 1/2) 3 1
= = .
(1/2 + 1/2 + 1 + 1) + (1/2 + 1/2 + 1 + 1) + (1/2 + 1/2 + 1 + 1) 9 3
Thus, as stated, the probability of winning by switching must be 2/3, so
ours odds double if we switch.
Although the above calculation shows that we can compute the proba-
bility with only the most basic counting, some people prefer to use Bayess
theorem on conditional probabilities to find the probability in question.
Thus, if we label the three curtains A, B and C, and if we let X, Y, W be
random variables returning, respectively, the curtain chosen by the player,
the curtain opened by the host and the winning curtain, then we want to
compute Pr(X = W |Y = A), Pr(X = W |Y = B) and Pr(X = W |Y = C).
We will compute only the first, since the calculations are the same. By
Bayess theorem,
Pr(X = W ) Pr(Y = A|X = W )
Pr(X = W |Y = A) = .
Pr(Y = A)
Another unstated assumption of the problem is that the prize has been
placed uniformly randomly behind one of the curtains, so that Pr(X =
W ) = 13 . On the other hand, the fact that the chosen curtain (X) is the
winning curtain (W ) does not change whether or not the curtain the host
opened is A. (If we knew more what, specifically, the winning curtain
is then this statement would fail.) That is, the events X = W and
Y = A are independent, so Pr(Y = A|X = W ) = Pr(Y = A). Thus
Pr(X = W |Y = A) = Pr(X = W ) = 13 .
Finally, there are many explanations of this problem which purport to
give some intuition that might lead one to believe the somewhat unexpected
calculation above. To this authors mind, the most instructive of these is to
realise that we are really being given the choice between two alternatives,
namely opening a single curtain (the one we originally chose) or opening
two curtains (the one chosen by the host, and the remaining curtain). It is
clear that the latter decision has twice the chances of winning. However,
it must be emphasised that intuitive explanations like this should
never substitute for actual calculations of probability. There is
much in probability that is counterintuitive, and as well many problems in
probability which have two intuitive but contradictory explanations. Only
4

formal mathematical calculations can guarantee a correct path through the


intuition.
(5) (CRLS C.3-2) An array A has distinct, randomly ordered entries,
which each permutation of the entries being equally likely. That
is, the entries are uniformly randomly ordered. What are the
expectations of the indices of the maximum and minimum entries
in the array? Let m and M be the random variables giving the index
of the minimum and maximum entries of A, respectively. By assumption,
Pr(m = i) = n1 = Pr(M = i) for any 1 i n, where n = length[A] (and
Pr(m = i) = 0 = Pr(M = i) otherwise). Therefore, the expectations of
these random variables are the same, namely
n n
X 1 1X 1 n(n + 1) n+1
i = i= = .
i=1
n n i=1
n 2 2
That is, one expects the maximum or minimum (or second-largest, or
seventh-smallest, or ...) entry of a uniformly randomly permuted array
to appear in the middle.
(6) (CRLS C.3-9) Show that, if X is a random variable which assumes
only the values 0 and 1, then Var[X] = E[X]E[1 X]. By definition,
Var[X] = E[X 2 ] E[X]2 . Since X assumes only the values 0 and 1, X 2 =
X, so
Var[X] = E[X] E[X]2 = E[X](1 E[X]) = E[X]E[1 X]
(since E[1] = 1).

  "!
#"$&%
')(+*-,/.1032547698 *;:
<>=?@<"ACBDFE .HG =?3IKJ
LM
NPORQ9LTSUNHLVXWZY\[^]`_bacZd`_7egf cRhiQj+kmlnLoqprM&stLTpLTkuvLTS
l`wNHL^MnLTj uvLTS
sxwU
yvoqkz{arcZd`_bef chT_7|~}Rvf+^{uvOotk
yvL^NPu-uJLLTstLTpLTkuvy-otkuvO
uvJ
LJ
L^j+Mj+yO ststOTy
VXWZY\[]Z_barcRd`_7egf cRh <t3?
 */ G>;* =
ON
, uvO{ *;/4
acZd`_7egf cRh _7|~}R;f<qKb qx?
LTkS
ON
NHL^uvUNPk
< ?O1uvJ
LgMNHOZQLTSUNHL^yXVXWZY\[^]`_bacZd`_7egf cRhjkS{VXWZY\[]Z_barcRd`_7egf cRh j+sx
-jwZyQ/NHLTj uvLuvJ
LyvjpLJ
LTj MJ
LTkNHU
kiO kuJLyj+pLotkM
UuP 6
D *vg*v-8 *;:4 H44 *K 96:74 VXWZY\[^]`_~arcZd`_bef ch 6T69 *
VXWZY\[^]`_bacZd`_7egf cRh`<q)?
= *v9 G>;*9 ` *v+/4
, ON
x *v+/4 t ,PX4b6 =
acZd`_7egf cRh+Y\C<tK7?
LTkS
ON
NHLuURNHk
A 69> *;:4 *n9:7:~P >=9 , ^ R *; *v+/4 ` + >6 x *v+/4 t ,P
= /34 *7+ **; *v25(+4769X6/ arcRd`_7egf cRh+Y\ 69 * 6/ VXWZY\[]Z_barcRd`_7egf cRh
*5+2 9+9* =;T 4 4 * /:b9*4
6/4b&2 +:7*v 4763698 4~/K4 */^G
*/ , v= 4 *6( 47( 46/ VXWZY\[]Z_barcRd`_7egf cRh
0)34 *n6/4 *;: 9 4 *7(2v25*vb7*
/^G */+:b6 (2;*v38T VXWZY\[^]`_bacZd`_7egf cRh
/:b* = , ;= / ;= , <x *v:7* * P*:7*v+:b*v7*;^47*-4 * */9/:7G
:~PTx6:2569T*;+*;2;* ? & 9>44 *69(+47+( 469 VXWZY\[^]`_~arcZd`_bef ch
< 8 ?RJOTuvJ
j u3uvJ
L--ONHy;u;bQj+yvLgNHU
kk
otk
zuotpL-OVXWZY\[^]`_bacZd`_7egf cRh oty
<xX 69 R?5- *-T+6 x:b694 *47*;T4F4 H434 * 6:b>4>G2;>*:b(++++47g*
6/ arcZdZ_7ef+cRhT_7|~}Rvf+^<t-b  ? <t 6 */ G>;*/ t? 4*v>4b6>*v*
(25479* 4 H4 *v9 G7;*9 ZK= 69 +* 6/ VXWZY\[^]`_bacZd`_7egf cRh+ 76
4 *&476/4~ / 69:~>4>G2;97*
:7(++47g*n6/ VXWZY\[]Z_barcRd`_7egf cRh  R <x 69 <x~
=?7? E 25*4 *256>4b/^4 + *vrr*92  X X4 *b/* 4 K8 69(+
2;98*):7* :74>4b*; Z 6 <x@=P?> <><xg=??n <xX 6 R? 8T
E 4b: + 9++:b6PTH4b6Z
< , ?@<"ACBDFE .HG, ?
< ?OTyvJ
OU
stSOk
LiNHLM
NHLTyvLTku@j/~j NPwJ
L^j+Mj+yj+kj NPNHj9w 9*v
*/ * *;+*+(24b* 4 */:b:bP 8T *;4>47+ =5 8*4 *:76T694
6/&4 * *v/9 * P9*K+(+4F4 *-H (+*/4)+6 * ^476 " *;4>4b+
<x&=?9 8 *K4 *-H (+*gH44 * 4 2 69+6 * x69: =-
(+4- cR`f+}`&<x?K\>H -= /r cR`f}`<t?-gWZ[^[ 6/4 *;: 7*9
>47*96/&4 *g f+^ 9 Yx ` x(+254769 * P9*K17 *x(+254769
 ZY\[^] 92v25*;+47+4 6{/:b9(+*v4~ 4 * *; 69)4 *9:7*v4/i9
*5 = +2vH47+4 * *v7:b*vi2 Z *;  ZY\[^]<tbT?
<xRi=?Z@
< 8 ?  Jj+uotyuvJ
L{JLToqzJuOXj9bj NPwJLTj M OXk
OZS
LTyotkuvL^NHpy1O X
j+k
S T B *54X(X7P4 H4X4 * G9:7 *v9@2;697>47+69 6/:76T6/4 9
*v 4 + < 0)+*2;69( @ 767P4 9 *v 4 =  4 *;:X-
0  69


9 *9 :7*X2567>47*v4 ? *v4 *K2 +:7*v69R4 *X:b>4+6 * <
4 9 6/
4 *; ? /:b*-4 *1,H   <q =? >4+6 *v 769^ *v/ 4 8*;4 *v*;r,
/ F= +6 * 9 *v 4 = *2 :7*v69Z4 * <q)i=P? >46T+* < &4
 694 *v ? /:b*4 * <t {=P? >4    <q n{=P? >4+6 *v 76K/T *v9
4 8 *54 *;*v n ,K9 n{= +6 *v 9 *; 4C,+& (25479* 69*
7*;*v4 /4)/T */ 4 8 *54 *;*v <t  P3=?=    =
/ <t  {   v{i=?      +6 *v 9 *; "4 !Z ( 4 *
*v 4X6/47:b*;* 4 * *;*;^4~X# ! \ 69  <x<t=?>?  < * 
b/4 H4)4 *-47:b*;* 4 6 :b6T6/4 9 *v 4 = 4 *; * 69( P*
! \ 69 <t<tKi=?Z=%? $ ?
< 2 ?'&)o ( L 3j+k
SQ9O prM
UuvLuvJ
LNPU
k
koqkzuvoqpLO b3j+kL *Q9oqL^ku@otprM&stL
pLTkuvj+uvotO kO
+)dZ`-c , _bacZdONj9bj NPwp/j .bJ
L^j+M 0)(+:) *5G
*;^4b/47696/ +FdZ`-c ,_~arcZd@ 6T6T 0(>4 *)4 *X69+*3x6:8+/:b *v9 1
+FdR-c , _barcRd<t3?
={ot *v/+G7v*9 3 2=
, NHL^uvUNPk *v9(+ *;5: 46 *v:7:b69:
LTkS
ot
/ =5 9 *v9 G7;*
*v9 G>;*9 ` *v9 G>;*9 =
. arcRd`_7egf cRh+Y\<qKv=?
6 NHLuURNHk
8+( 44 * arcZd`_bef ch+Y\ 69:b4 < 4 ? 8 7*;:b*;^4v: 9+69: G9:7
*/ 4 6T69 9*
arcRd`_7egf cRh+Y\n<qK>?
= 25:b*v/47* ; =   /
, ONX = 4b6
; /`  ZY\[^]<x~^?
LTkS
ON
<>= ?A@ C BD&

. ONX = 4b6
6 ot ; 9 *v9 G>;*9
E oq ; 9 <>= ?A@ C BD"
F <G= ?@ C BD& ; 9
= LTk
Soq
=9= LTstyL
=, l
NHL^j/H
= LTkS
ot
= LTkS
ON
= ot <G= ?@ C BD"I
= . 9 " / <G= ?@ C BDq
= 6 acZd`_7egf cRh+Y\C<tK <>= ?A@ C BD>?
= E LTkS
ot
= F NHLuURNHk
n4 * ot 47*v>469 +* = >(2;25*7>x( 4 *;4 *4b:7*v*:76T6/4b*v@H4 <>= ?A@ C BD
 *; 4K6+* *74 9@4 * *v 4-6/C4 *147:b*;*:b6^6947*/4  (
* *5K4 J < ! ? 8*g>6 ( 4b614b6-4 *X:7*25(+:b:7*v25L* J < ! ? J < ! r=? <tT?
J < ! =? <>=?<t 4 /+:76+:7H4b*86(++9:7 2;69+4b6 ? 4 *;M J <! ?
K/{6H9*v:7*4b/47*x69:4 *:7(+++47*16/ arcZdZ_7ef+cRh+Y\<qK>? 6r
N
*/ >(2 4 H44 *7(+8 *v/{:b6T6/47* /4 9 *; 4O!Z0)+*12 *2~
8T4 *1>(84b4b( 4769r*;4 6 4 H4#J < ! ? < ! ? (4 * 69:~>4>G2;97*
:b(++++K4b*36/ acZd`_7egf cRhY\9C<t-;=? < ! ? *;:b*
!n4 * *; 46/
4 *HTG *v9  P/:74 < ,H8 ? ! <x 69 R? E 25* +FdRc-, _barcRd
6T*vX6 @256>4b/^4K/6(+^4K6/ 6:7r9++4b6@4b6 arcZdZ_7ef+cRh+Y\
* P9*)4 /44~:7(+++g47g* 76 <t 6 R?

  !
"!#%$
&('*),+.-(/102)435)7678*+2929:
;=<>?;!@BAC(DFEHGI<KJ + >MLON
P QSR*P*TVU
WXY[Z]\
X^WH_S`badcfegheigkjl%;Vm,nVodnqpr>.stWfQUds1uwvxN
Wfu
P*TVTWHuQ4s1yVWH_zyVu{m,| o~}4}7}=p~P s1WWfiU
P*TX^\yY!`baceigheigkjlw_7XQ7N
P QZ?
;o[?pr>q +t yVuQ7N
yV_2P*_W )[ )7K65)q*)3/ )72/26*3 `badcfeighegkjli
6 G
`badcfeighegkjli!;Vm,nVodnqpr>
<zm| p
+ ox<
 o<
YXsFo q/ p<
: yYm,| 2d
<
E qr m| 2 2 m,| 
<
H
W V
T 
_ W
<9 yYm,| 2
<2< <
<+ =r m,| r r m,| 
< WHu
\yY
< WHu
\yY
< : WHu\
YXs
< qr m,| <K 2 m,| p7
<tEs1WfQ7Us1um~nf=; >q +1 <t
*)/6qI2I2rI2/6qq3 `badcfeigheigkjdl 8*) yY q)/2*).2rI/2'*)~/2I*)x:
q)dM*)4q*)76 m| 2
d I*) 1 < 26q)*/r
*6q)=)7f I*) < qr m,| <K 2
m,| p! r,I*) <1E 6)K'*6q m~n <tG
D 4)*) yY q)
/2[*)B2rI/2'*)/2*I*)M:
/r**)B/2622/26*3IqH'%q'44)7k'M*)72H)4f6qI)7
r6))7f'281I~1
4=)Bq)M0t2')B/2M*)7,*) YXs /H/2q)76q3I1)7%h pd< 8f=/q)M0t2')M/r
Z 6q)4q'*6*)I Z x<(pHG ,/2'*6^3/ 4rqI/2^8*) yY )7=/2[II*):hd2t
'*q'44)7k'8H5*' Bq) yVY )7=B/xI*) < 9[h2t q'44)7k'*!8Hd2)4f6qI)7r6)
)7f'2 G H',142q)x*)01rI'*)/2zM*)4*) YXs I/H/2)463.Irq)7,I
Fob.< 8tM*)76q)2i*)B0t2')/r M)4[*) YXs /H/2~q)4631q)^h p.< 81q/
q*)M012'*)M/2 Z 6q)4q'*6*),h Z; > +t ;opd + > +1 <(=;opr>q +1 G
*)6)7 )46=*/'*h*)7?q1x/H/H01r6hrf[k/26q*) YXs I/f/I/2'*6
3/H*)2/26*3Iq()4fq6I)7/r m,| o~}7}4}  26q)()qq2 m| p rI)76qI)7
/r m,|I; ?<t>}4}7}  26q)M)'rHq/ m,| p7 r2*)7fq6)%/r m,|I; ?<>i}4}4}7;<> r6)
26)7rq)46qr m| pG F ~)463rqI/2^8rq*h%=*/11%/2'*6%3/ )7.rI2/6qq*3
r6qqqI/2MK/266)7 G
; + >?;!@BAC(D,EHG + J + >iLN
P Qy_Q7N
W[s1Uu
uyuQ7yVW[XY%dgk%jdcfeXuP*u]P ststPP*TT
XYBvxN
X_WWHuQ7styWH_,P s1WWHiUPT!C )73)43,5)46B1Bq*)rI2/6qq3 dgk%jdcfe
/H/HII2)
^gk
jceb;m~nodn=pr>
<yVY^op
+ s1WfQ7Us1um
WHu\
yVY
Vm,nqZr`badcfegheigkjl%;Vm,nVodnqpr>
: m^gk%7jcfe%;Vm~nodnZ<>


s1WfQ7Ustu^gk
jdcfe%;Vm,nqZ<2n=pr>
C )77rI1q1^*)6'***I*qI3)/r `badcfeigheigkjdl h ;kd>KG ;=<> 8 `baceigheigkjlb;Vm,n4<2nqd>
6q)4q'*6 ZzbGF /6q)7/102)7678%rI)4fq6),/2 m,|<}4}7}7;Vz<> r6))7f'2 G;V I
=)K/]q)4fq)7K)h3/26qrfq/rII/1w'q/S2=)76=q)6)74'*6q6)4K),6)4h1/
5)7/1 G> H'78
M ;Vd> )4*/2q)q*)6q'**SqI3.)/r ^gk
jce /22 J
)4fq6]26q6trIb/rM/q))76qI)726q))7f'28*)4 ;Vd> ;V<t>
;Vd>G
*)q)4=/1'=I*.q*)~q'*5=qq'*qI/23)K*/ 1 ;kd>b ;V >KG
; >?;!@BAC(DxEHG + J >dN
XHvQ7N
P QQNW.s1U
uu
yVu
QyVWXYBdgk%jdcfeSXuzP*uP sts1P2
vxykQ7N\y_4QyVu
rQ,WHuQ7styWH_2^_XstQWf\yVu\
WHrs1WHP*_yVu
]Xst\
WfsHdyV_ ;k >KBD '*/f=)
qr m qrqh)q)?K/ qI/2*)?=rq)73.)7f G *)7q*)zr2/2'*)SI
`badcfeighegkjl /r%*) yY )7=(/2I):/r `badcfeigheigkjdl^ rItHBV2h78q/8/K/3 J
*I)KqI/2F/2*) YXs I/f/^8
9 G H'[B)=r m,|<K r m,|  8
2z6q)4q'*6
Vm,n4<KG -/2q)qr m I*/z/*2)76q/26qq)F )746q)2q/26 )468b=/?)S42^
=)4.']6q)K'*66q)7K)2)47 ;V )6)7 )46.I.)7K/'*622)zq/K/2=h )46q)72q)
mw : n n n + n4< 2M2)4*r3*I)*6/2'**/2' *I*6q/5*I)43 G >
/*qI*6/25)738FI)K I/H/21M12*)7*)KH G )6'*
^gk
jceb;m~n + n=d> 8rM*h.q'6qx42h `badcfeigheigkjdl%;m~n + n=d>KGbD 4)Bq*)M*)7
m,|  Iq)/I m,|<K 8 M*II*)hr62))4I)43)4f/r^*)[r66t8rq)2rI/2'*)
`badcfeigheigkjdl /2*q) yY q)%/2I*)M:M/r `badcfegheigkjli I
*/1rIBt dq'7K)7=k'*8
=/B)[=r)7)76q m,| + n4}4}7}Knqm| <K Mqq)48r^8 /2SK/23*I)K/S/r
q*) Y!Xs I/H/2^8 S<2G H'MB)[=r m|  Mqq)4826q)4q'*6 Vm~nqdG
-/2q)q1 m b*/2r*)7.12*I.q*h7rIHq/ `badcfeigheigkjdlbG x26=I4'*hr68
q*)M)4)7fq6)%/r m| + }4}4}7;k<t> r6)q*)r3)2
q)M/2h,)76qI)778rq/*)4r6)
=/6=)7, )746q)2q/6 )76 G
D K)/2'*6%*)4Hb7rI I/ dgk%jdcfe%;Vm,n + nq(<> 8
hM*/1r*6q/*6qh1)(/x=)4'*S/2'*66)7K'6q6)44) G
D IK)*)/x42hBq/ `badcfeigheigkjdl =qI^IH02/0)7/*I ;kd> 6'***I*.qI3)28
)t0)18*
;kd> )7*/r)7q*)[6'***qI3)/r dgk%jdcfe /rSr66t
=/6=)7 )K6)7=I*./26 )468fq*)7 ;kd>b ;k + >^ ;kd>KG K)~2rI^8H/2)
02)76q)75Hx*)~q'*5=qq' /3)4q*/ qr ;kd> ;k >G
; >?;!@BAC(DEHG J + >?^N
XHvQ7N
P Q{^gk
jce
I_Wf_7QK2P*_Ws1Uu
u
yVu
QyVW{yV_
;k I/2 d>K bwh(2t */2*)4rqI02)~2qrqh)7*),6)74'*6q6)4K)[ ;Vd>
3d7 ;Z[<>b ;kZr>,^ZS<2n7}4}7}Kn=%( ;Vd> 8^*)4d8
qK)q)x6q'**
qI3)[/r `baceigheigkjl h( ;kd> 8 )t0)(1 ;kd> IM2' )46)7=qI3x1)k/6q*)
6q'**I*xqI3),/2 ^gk
jdcfe /22*' /2b)7*r bGA )K5),4/2=2f
='1M*), ;kd> q)76q3I)702)4f'rIx5/2' )75)4I/15H bG 3xrH.
=3x2I)46b*)K)7r628*B)~3xtqq'*3)[q1*I(5/'*'rI*/2h*k/262
bG
D '**/q)1)]t02)]K/2rfrFH'*3,5)46  < ='1
;kd>  I 8 <x Gx; -/2q)B) /^ t0),/2'6'q'2
6q/5*)73M
q*)[I/2fr6*35)4I*91 < 8*qK))[26q)q6H,/x)7=r5h=S  
B5/'*i
/1B)40)468 ),*/xt02)/5)4r6)Kk'iq/t0/2h'*2I*xI ? 9 G > rH
[=3x2I)46b*)74)7q26q8 )[3xt)4q'*6)qr G;V )~6q)2q/2k/26M*hMI
5)K/3.)~4)r6)46h1q)76 G> *)4SB)t02)qr
; >
 3I^7 ; 9 > ; [<> I ; [<>Kn ;ZH[<> I ;VZH[<t>q ; Zr> I ; Zr>BfZ + n7}4}4}4n [<2
 }

-/14/2qh )46dq*)k'*KqI/2   ;kx<> I ;Vx<> ; [> I ; [> )4*)
k/26 < G [ )46I0trqI02)h   ;V<> I ; >[
 ;k<>B I ; > 8bM*IFh,9S6q)Kh=)7zM*)4 < 8% G ) G 8
{ ; <>q + Gw *)z=)K/2 )4601rqI02)Sq)6q)702)rhqr*IhFI/ 4r
3*I3,'3 GD K) ; <t>q +h~SK6I7rb/2I8d~I['rI?S2I/252
3*I3,'3 G f'
3I^t ;VZ<t> I ;VZ<>^ ; Zr> ; Zr>2Z[ + n4}4}7}Kn <r
 +2 + < I  + <  ; <> I  + <  }
D IK)Mrhq/( ; 9 >7 ; x<t> ; x<t>  ; x<> !  ; 5)742'q) ; 9 >  9 > 8
)[t02)qrV2K
; >  ; <>  + <  "
# I ; <>^  " #  ; ; <>q>d I ; + >K; <t> }
D IK$) ; <t>B + 8)t0)
; >  # I% ;  >}
D IK) ]2 & < 8%)xt0)qr"  98
q/ ; '>   % G
H' ; 5Hx*)~q'*5=qq' /3)4q*/ > ;kd>b ;V / d>G
; : >?;!@BAC(DEJ<)> (Xu
_7y\WfsxQNWYXTVTXHvyu?R*P s1yVPu+Q *
P stQykQ7yXu
yVu
P*TVXstyVQ7N
- ,
. jiad0c /21=`badcfeigheigkjdl;Vm~nodnqp1>
3 yVY%o  p
4 s1WfQ7Us1uwVm~nWfss1Xs2
5 H
W 
u

\ V
y Y
6 m| o
798 o
: p
; \
X
< vxN
yVTVWSm| 2 
= .O[<
32> H
W

u d
\ x
v N
yVTVW
3?3 vxN
yVTVWSm| 8 d
3@4 8 8 <
325 WHu
\dvxN
yVTVW
3"6 yY 8 z
3@7 _7v,@P *m| 8 P*u
\m,| 2
32: .O[<
3; 8 8 <
32< WHTV_W
32= s1WfQ7Us1uwVm,n!H
4A> WHu
\yY
403 WHu\
\
X
B s1XHRWQNW]Y!XTVTXHvxyVu
d
; 5 > CKYopHQNWHuzQ7N
Wyu\
yVWf_ 8 P*u
\xP s1Wx_7U
tNQ7N
P Qv,Wxu
WRWfs,P*2WH_7_
P*uWHTVWHWHuQXYbmXUdQ_7y\WQ7N
Wx_Ud%P sts1P2m,| o~}4}7}p!MD IK)M2fr*)
q/ 8 I*)(6q/26r3I46q)73.)7f8H22f2*2)M/ Ixq*)*6/2623
)K6)43)4f78^r]q4)B)=26=M 8 o r p 8^/25H0HI/2'qr
D
r I 3)7 8 zo r p 8fq/[B)M*)4)/2*I,*6/102)B1rrI qI3)7 +zo
r 8 pHGM *)[)7=(q*) vxN
yVTW I/f/S/2I*) VrII(/2q*),6q
q6q/'*2x*) \X I/f/ o; q4) m| o> 8*q/ hB*/rM )K6)43)4fq)
 o /?*)6~I/H/2 GS ?*)/2q*)76~ri8qK)28
/2z*)6~q
q6q/'*2S*) \
X I/H/2^8 8 o 8B)~t0)[qr m| 8 
 8q/x*)~)7=Iq*)
vxNyTVW /H/2]/2I*) <2< VrII(33)7 h1)4IS/2*)~6=qq*6/2'*Sq*)
\
X /H/2 G
M )46q*) vxN
yVTW I/f/b/xI*)7 r << t02)B)463.Irq)7^8B)t0)1
m,| 8 .O r m,| 2+ OdG -(/1*)46)r6)//=I5*IqI)7 G q) yVY
q)/II*) < h'*q'44)7k'*!8 *)4S)K )K' /4)72q)7Mq*) s1WQUds1u
I6q'qI/2d8Bq/)26q)S /2) G -(/rq)Sk/6x'q)5)7/1qr78*I42q)28
FodG
bq),)7=hq'7K)7=k'*8B),qB2 m,| 8  2 m,| 2 8*)4?K6)43)4f 8 2
)K6)43)4f G( H'(q*)76q).r6)[ I4)7F E 8 G< o rI H [<.p
q'q1 m,| E  2 m| H J dG, *)7K HF L  ErM E 8 H G
26=I4'*I2678k/26*)6)43x2*)46/r*).*6q/26r3).t0)~q1 H2
8 E G -/2q)k/6('q)[5)7/1q178Ir6qqhK'*hr68 p k/6Mq),6)43xrI )76
/rq)M*6q/26r3 G -(/1*)M/2*I,t[1 m| E  /6 m,| H  MI*)702)76b5)M3/102)
Iq)6)43xrI )76/2q).6q/26r3I8^1[=/3.)./2I8i)6q)2*) yVY
q)/2?I*) < M*)7 8 H/26 E G (/1)702)7678?qI[72q) 8 HF
/26 E 8 8^6)7q)0)4I28^q/*) yVY q)7=VrII Gx H'*)4q*)76 m,| E  */26
m,| H  MId)402)765)[3/102) Gb *)4*) vxNyTVW )7=/2I*) VrIIM)4*)702)46
E8r*) vN
yVTW q)~/?I) << V2hM*)7*)40)46 8 H Gx f' 8 I
*)702)46IK6)43)7)7) H p 82 I*)40)46M )746q)73)4fq)2=% E ]oG
; >CKYMowpHQ7N
WHuMvxN
Wfu . jad0c /21q`badcfegheigkjlQWfstyVu
P Q7WH_o?wpf
x26= ; :15 > 8f)(q*/1B)7q178H/q)4631qI/2d8 .Fo /6 pHG op 8
I)7*)46(72q) xpHG
; > CKYopHQ7N
WHuvxN
Wfu . jad0c /21=`baceigheigkjlQ7Wfs1yVu
P QWf_WfRWstWHTk
WHWHuQ?XYm,| o~}7}4}!2,y_zTWH_7_?Q7N
P*uXsWHiUPTQXwWfRWfst{WHTVWHWHuQ]XY
m,|I;~<>}7}4}px )xKhrI3q1q*).k/I/1M=1)43)4fI6q').r)70 J
)46])4 )7K'*qI/2F/rI*) < O N02)46)76qz/r m| o~}7}4}4; 8 <> I,)q[q2
/26[)f'r%/ 8
)402)76q])4fq6]/2 m|;I,<t>}4}7}p h[26)7rq)46r/6[)7f'r
q/ 8 m| 8   2 m| 2G ; -/rI4),1[B)26q) PQSR%4I23I*1
qI=rq)73.)7fIbq6'*) 5)42'=)M*)7)7 ^ 5)2 M*)7x)M5)4.q) \X
I/f/^8r/*,/2I*) < G >~ )M6q/10)1b*I1q)73)4fIbI/H/2H01r6hrf
I*)['q'r^t
T CKu
ykQ7yP*TVy_7P*Q7yVXuGd *)6=do3 )B)6)7[I*) < 8*)m,)7| f=  m| 8 d
Bq'7K)7=k'*
k/26)40)46 8 8 8^2*).q)  2
='4K)q=k'*(k/26)702)76q wOf p 85*' q*)]q)7= m,| 8  2
m,| 2  B)46)'*q'44)7k'* G
T P*yuQ7WHuPuWGF@ /2qh )466q)2*I*I*) < ]r q)76,*)6=,qI3) G
&()7*/r)5H 8VUXW Y 2 UOW Y q)01rI'*)7,/r 8 2 *)h2=[qI3)B)
6q)2*)I*) < G 1B)?t02)]6)7*)7I*) < r23.)r
qr 8VUOW Y UOW Y 2B))76=k/6q3)zq*)=rF/FI*) < : G *)7
rI)76qI)7~/r m,|<}4}7}7; 8ZUXW Y <> 26q)xI)7[r/6~)7f'2/ 2
rI)7fq6)~/r m,|I; UOW Y <>}7}4}qp7 26q)6q)1)46~r/26.)7f'rq/ d
5*' .V28=I4)B)qB2*) m,| 8VUOW Y  r m,| UOW Y  8b)40)42B)4 J
q6)./r m|<}7}4} 8VUXW Y  r6)I)7,r/26.)7f'2Bq/ 22)76qI)7
[
r/ m,| UXW Y }4}7}=p r6).)qrz/26)7f'2%q/ dG ?q*)x3/f[6)7K)7f
)K )74' qI/2/rb*) vxN
yVTW I/f//I*) r << 8)[k/'*S1
q*)~q)7= m| 8 
 2q'7K)7=k'*ik/26)40)46 8VUOW Y <~ 8 d 8 82
q*))7= m| f  BBq'7K)7=k'*k/26M)702)46 xFfi UXW Y < 8 5*'
q*)q)7= m,| 8  2 m,| 2  VrI) Gb H'bB)Mt02)M3xrIf2*)
q*)[IH01r6I2 G
T]\ G
Wfs1yuP QyVXu_G ^ /6bq*)*6/226r3q/[)463.Irq)28)(3,m,'| o~=}4}7}7t; 0) 8 < >
*)7~*)/H/2H01r6hrf%t ^1%)40)46[)4fq6[/r 8
I~)q~q2F/26~)'rb/ r)402)76q])4fq6]/2 m|;I<>}7}4}p I
26)7rq)46qr/26x)'rq/ 8BMI) m,| 8 `  r m| 2G
8 w 8q*h[3)72q1 m,| 2 8
q/S)40)46)4fq6]/2 m| o,}4}4}!r I
)4q*)76,r)76q]/r m,| o~}4}7}7; 8 <> /26 m| 2 8)44)xI[I)7r/26
)7f'2iq/ 8M*hIS'*6qSI)7qr/26M)f'ri/x)40)46)4f6q/r
m,|I;BF<t>}4}7}p!G 8  8fq*)7)40)46)7fq6/2 m,| o~}4}7}!2 h2)4f6q
/r m,| o~}4}7}7; 8 <> 8
*)7K)xh[I)7q2F/26[)'rb/ 8
M*Ih[I
q'*6)qr/26M)f'r/x)402)76qx)7fq6/r m,|I;<t>}4}7}=p!G

 
 "!$#&% ')(!+*-,!/./0"12243
576895;:=<?> @BA"CD6FEG68-HJI?K LMONPL/IRQNSK"TOTUQVN/L9WYXNN/MUZRTOQ\[?Q]WRL/I^X_K`TOQ]Ka_MUbcK
[?QVd4MUNMUXbeL+f)QVQg_hXf-KidXSPW
K f)MUNXbPNXfL)jP@ "kak']l7!nmpoaq)m=rs! .t!quGo"!vmto"!xwy!q)z
{}|7~t|+/+/7|" 0,""m"!/(!/.xkaq4ltlt!/vimto".p'"4oqa'Vv"!-'zmto"!-z}'.p* |7~"|C o"!/
l7rnympuGoay"mpo"! |7~ l7mqav |h av!+]mt.py!l&'zrs'4"wDvlmpywDw,".pD"ealmt'mtoa!iwy!q)z
{}|7~t|+/+/7|" 0?," mmtoa!+9mto"lr='"wv)u+'.p.t!umtwDiDav u+q)mp!o"')r`mp'l7'4.7mmto"!
q.p.pq$0"u+']mt.Gq.p$mp'$mtoa! zUq4umYmpoaq)mr=!xq.p! r='.pVyarnmpogqv"!/uFlty'4mt.p!+! z}'.q
uF'4*kq.pDlt'ilt'.tm Cn oValnr=!$*al7mxoq(!kaq4ltlt!/vgmtoa.t'4"omtoa!"' v ! | ~ 4| qav0
l7D*&ywq.pwD0 | |+/+/7| V~ 4| C oValsmtoa!lt*qwDwy!lmk'4lpl7D,"wD!v !/k mto'z
qwD!/qzD
qv !/u+Dlty'4mp.t!/!Dlqmwy!ql7m
6CR@ yau+!nml
!/q4l7mp'$l7!/!=mtoaqmRmpo"!+.p!q.p!v !/u+Dlty'4
mt.p!+!l 5 z}'4.xG+a4}??]R0"z}'.n!+"q*&k"wD! 8 DrnoaDuGoilt'*&!wy!q(!lsoq(!wy!q(!l
'zv !+k"mtog 6 0"mto"!$lt*qwDwy!lmnk'4lpl7D,"wD!v"!+k mpolnDzUqumn!+ q4umpwy 6C
5 1 895;:=<?> @A"CD6FE48
IRXV^L/IRK LL/IRQ]fQMONxbRXdXSPW
K f)MUNXbN/XfLxIRXNQf)?bRb?MOb?
L/MOSQMUNTUMUbRQVK f&_;Xf&K L-TOQ]KaN+L$IRK"TU_=X_YLI?Q WYQ]f)SLK L/MOXbRNX_=KiM}QVb 
QVTUQVSQVbL=K"ff)K4aK"TUTX_I?XNQ$QVbL+f)MUQVNnK f)Q$[RMUN/L/MOb?dLHJIRK LMU_-Qf)Q4W
TUKadQ
IRK"TU_4nZ 6) Fj6 1 j m-lt uF!/l$mt'lto"')rmtoaqm$ mto"!/.t!l$a'uF'*&kaq.tlt'
l7'4.7mrnoa'4lt!.p""ay"&mpy*&!lnwDy"!q.z}'4. q)mwD!/q4lmn 1 'zRmtoa!"k!/.t*- mpqmtD'al
'zYlta uGoqq.p.pq C @ "k"k'4lt!-mtoaqm mtoa!+.p!lxlt'*&!-u+'*&kaq.tl7'4il7'4.7m rnoaDuGol7'4.7mG l
1 'zRmto"!k!+.p*"mpq)mpy'4alnD"'*&'.p!mtoaqgmpy*&!$ C= o"!+mpo"!+.p!$q.p! 1
wy!q(!lsqmv !/k mto"'.p!/qmt!+.smtoqgF Cs mtoa!'mto"!/.soqav0 DqV&,"yq.p&mt.p!+!0
mto"!/.t!$q.t!xz}!+r=!+.mpoaq14 "' v !l 5t x );U) wy!q(!l 8 ~7 q)mv !/k mto"~ ' 4.t!q)mp!+.smtoaq
C o] lr=!ioaq(! 1 1 0'. 1VDh ~ 5 1h 8 C ')r=!+(4!+.0
]\ 5O 8 z}'4.qV 0 Dkaq.tmtuF"wq.0Vz}'. 1 h 0"l7'mtoaDlnlnD*&k']ltlty,awy! C
5O4895;:=<?> @A"C 1 Eh]8xgQVNdf)M}ZYQK"bK"TOXf)M}L/IRSLI?K"L M}Q]b MUbLQVQ]f)NMUbL/IRQ
f)K"b?Q 2 L/XWRfQ]WRf)XdQVNN/QVNPM}LNPMUb?WR?LMUb^L/MUSQ5 "8iKab?[LI?QVb
K"bRN+Q]f)NMUb&5768LMUSQK"b?Q]fX_ LI?Q_hXaf)SI?XVSK"b\X_ LI?Q
MUbLQ]Q]f)NgK f)QZYQ]LGQVQVbeK"bR[`+j]
@ ak"k']l7!mto"!D]mt!+4!+.Gl q.t!lmp'.p!/vD
qiq.p.Gq& C> !+*&!/*,!+.'4".nl7",a.t'4 mtD"!z}'.u+'"]mpy"lt'.tm
xVF?] 5 p"8
6 uF.p!/qmt!& 5 68/+G]
1B&y 6F 2
B_hXaf 6 mp'wy!/"mpo
& y & y 69c mmtoa!!/av'zmtoaDl _hXf wy'V'k0s& |; rnDwyw
uF'4"]mmto"!V"*-,!/.n'zRmtD*!l | ' u+u+".Gly C
3 QVb?[R_hXaf
_hXaf-| 6 mp'
& |; & | 6F & |O^ mmpo"! !+avP'znmto"l _hXaf wD']'4k0Y& |O rnDwyw
uF'4"]mmto"!V"*-,!/.n'zRmtD*!lqD4mp!+4!+. | ' u+uFa.pl=D C
ABQVb?[R_hXaf
# f)Q]L/?fb
,V(]D'l7wDmto"!.ta""D"mpy*&!'zmpo"l-ka.t!/k".t' u+!/lpl7D"qwy4'.pmpo"*l 5 "8C
%'mtuF!mpoaq)mr=!oaq(!Dau+wyav"!/vmtoa!uF'a4m?&y 6F 0/z}'..p!/q4l7'4alrno"uGornDwDw,!/uF'4*&!
uFwD!/q.t!/.n,!/wy')r C au+!rs!oaq(4!mto"!-q.p.pq0rs!$u/qqal7r=!+.]"!/.tD!/l qlnDmto"!
lmGq)mp!+*&!+]mDka.t'4,"wy!/*mtD*&!
G"  " 5 8
6eMU_Y \
   

1 ltr=qk qav

~

BQVb?[RMU_
UM _s
3


QVb?[RMU_
MU_Y 2
A & 2

# QVb?[RMU_
6 2 f)Q]L/?fb & p e& 6FhC
z 2&'4.  0aym rnDwyw?"'moV".tmmt'lt!Fm 2&'. 0ltyau+!"'!/4mp.tD!/l'z
q.t!x' mGl7v ! mto"!.pq"! 2 p]hC
o"!+ mto"!V"*,!+.'z!/]mt.py!lY,!Fmr=!+!/ qav


5 DauFwDalty(4! 8 Dl mto"!-V"*,!+.x'z!+]mp.tD!/l 0*DValnmpo"!V"*-,!/.x'z!+]mt.py!l  0


rno"uGol al7m& p P& 6+;C

5U]895;:=<?> @AEp68 -Xb?NMU[RQ]fK"b K ff)K4 ` { ~ /+/F M}LI[RMUN/L/MOb?dLQVbL+f)MUQVN4




Q]L ZYQK 7[?Q]L/Q]f)SMOb?MON+LMUd xd4XSPW


K f)MUNXbPN/XfL&MUL/I[?QVdMON/MOXbeL/f)Q]Q =


5 q 8iWRWYXN/QiLI?K"LQVK"dITOQ]Ka_ X_ MONTUK"ZYQVTUTUQV[ M}LI\L/IRQWRf)XaZ


K Z
MUTOM}LG
   

L/IRK LiM}LiMONgLI?QTUQVK"_f)QVK"dI?QV[`IRQVb-QQ Q]d4LQ Xb`KRb?MO_hXaf)S




f)K"bR[?XS WYQ]fS?L/K LMUXbX_ IRXV L/IRK LeQ KadL/TU TOQVKQ]NK f)Q




TUK"ZYQVTUTUQV[6 K"bR[\L/IRQif)QVN+LK"fQ9TUK ZsQ]TOTUQV[ 2 @ Dau+!mto"!!/]mt.py!ln'z




q.p!v Dl7mtDauFm/0!/(!/.tk!+.p* mGq)mtD''z\wD!/q4v"lRmt'qv !+.p!+]mwD!/q)z0z}'.qxmt'mpqw


'zR .t!quGoaq,"wD!xwD!/q(4!/l C? zRrs!uGo"'V'4lt!q-a"z}'4.t*c.pqav '*ck!/.t*- mpqmtD''z


0Rmto"!/r=!oaq(!k".t'4,aq,aywDm 6 'z.p!/q4uGo"yaqV " !vP'"!'zmto"!l7!


wD!/q(!l+0 qavka.t'4,aq,"DwDm2'z?.p!/quGoay"-mtoa!'mtoa!+.Gl C


5 , 8 XfxKab[?QVdMON/MOXbL/f)Q]Q $aTOQ4L 5 x8
[RQVb?XL/QL/IRQN?S X_L/IRQ-[RQ]W?LI?N
X_K"TUTLI?QTUQVKQVNX_ $WRWYXN/QL/IRK L MONKe[?QVdMON/MOXb L/f)Q]QM}L/I
"! # %$ &

Q K"dLT} 6eTUQVK4QVN4K"bR[TUQ]L 9K"bR[ iZYQ\MUL/NeTUQV_;LKab?[


 '

f)MUIL\N/?Z?L/f)Q]QVN4 f)XVQLI?K"L 5 x8 5 +8 5 F8
 (
)*,+.-0/ 1325476989/

@ DauF! oaq4l*'4.t!mtoaq 6 wy!q)z0ymplwD!/q(4!/lq.p! al7m&mto"!wy!q(!l'z 0


;: ($ & $ <3*7+-0/ $ <=2>4,6989/

mt'4!+mto"!/.rnmpomtoa'4lt!'z GC ')rs!/(!+.0u+'altDv"!+.sq$wy!q)zy 'zv"!+k mpo


 ? 3@ ACBD

C oa!+0uF'4al7v !/.t!vq4lqwD!/qz
D 0m oql v"!+k mpo 65 l7DauF!rs!*-alm
3E&F GH.D =@ ACB7D

qwlt'9uF'4"]m-mpo"!.t'V'm'z x8C@ D*&ywq.&.p!/qlt'ay"o"'wv"l-z}'. C oVal


I  I

5 x8 5 5 78 |8 5 5 8 V8 04rno"!+.p! | lmpo"!V"*,!+.Y'zwy!q(!l
 3E&F G>H.D

D qav Dlmto"!V"*-,!/.$'zwy!q(!ly C@ yuF! | 0mto"!


$ < J$ &3@ ACB7D J$ &3E&F GH.D

mt'mpqw]a*,!+.n'z
wD!/q(!l=ymtoa!mt.p!+!0 r=!q.p!v '"! C
3@ ACB7D 3E&F G>H.D

5 u 8 Xfg 6
TUQ]L 5;"8xZYQiL/IRQSMOb?MOS9RS "K"TURQX_ 5 8RL/K Q]bXVQ]f
K"TOT [RQ]d4MUNMUXbL/f)Q]QVNM}LIQ K"dL/TUTOQVKQ]N4eIRXV L/IRK LMO_ 64
K! L I %$ & NM

L/IRQVb 5;"8 *&y ~ ~ 5 5}|8 5; |8 "8F@ "k"k'4lt!nmtoaqm lYqmp.t!/!


 O

rnymto 6 wD!/q(4!/l C kaq.7m 5} , 8 0 5 8 5 8 5 8 C z


I QP=R<P3S I I 

oaql | wy!q(!/l/0"mpo"!+ 5 8 5}|8 qav oaq4l | wD!/q(4!/l/0lt'


)
%T $ & $ & @ ACB7D $ < E<F GH.D

5 8 5O |8C oVal 5 x8 5U|8 5O |8 0lt'a04y&kaq.7mpDu+"wq.0


 @ ACB7D $ & @ ACB7D L I VU  <E F GH.D

ymDlnqmwy!ql7mnq4l,"D&q4l=mto"!$v" !/lty.p!/ vg*&y"D*a* C


$ < E<F GH.D WL I $ < XL I I

mpo"!'mpo"!+.&oaqav0wD!Fm 6 | 6 ,!gmto"!()qwD"!mtoq)m&*D"D*&Dlt!/l
5}|8 5O |8 C < !+m ,!iq9mt.p!+!rnmpo | wy!q(!/l&ltauGompoaq)m
5 48 5}|8 0Rqav ,!qgmp.t!/!rnmpo wD!/q(4!/lltauGompoaq)m
I I 3@ ACB7DCY[Z\F ]

5 8 5O |8CP o"!/lt!gmt.p!+!/l-!F lm&,Vmto"!v ! "mpy'4'zmto"!


$ <=@ ACB7D^YVZ\F ] I =E<F GH.DCYZ\F ]

z}"auFmtD' Ce< !+m


$ <=E<F GH.DCYZ\F ]
,!gmtoa!mp.t!/!rno"']l7!gwy!+zm&lt", mp.t!/!l qav
I V

rno"']l7!x.tDo]mnl7","mt.p!+! l C oa!+ 5 x8 5 78 5 t8
I 3Z\F ] 3@ ACB7DCYZ\F ]

5U|8 5O |8 0arno"uGo0",Vqlpl7"*&k mpy'40"ln!/]aqwmt'&mpo"!v !l7D.t!v


3E&F G>H.D^YZ\F ] $ & $ &3@ ACB7D $ &3E&F G>H.D

*&yay*-"* C
I I

5 v 8 f)XVQL/IRK L_hXafK\MUQVb`"K"TO?QBX_- c64L/IRQSMOb?MOS9RS X_$L/IRQ
_h?bRdLMUXb wD 5; 8 wD 5; 8MUNeK"dIRMUQ]QV[^K L a 1
": _

-XbRdTO?[RQL/IRK L 5O"8 5; wy "8 o"!v !/.tD()q)mpy(4!i'zmto"!Dav u+qmt!v


a`cbde` ` ` ` f`

z}"auFmtD'l 5 wy 8 gwD 5 wy 8 wD 5; 8 \wD wD 5O 8 0Vrno"uGo


 I hg

lY2k".p!/u+Dlt!+wDrno"!/ 0] C ! C 0 a 1 C? o"!xl7!uF'vv !+.py()qmtD(!mt!lm


`Kdb Xi ` Xi ` ` `

lto"')rlmpoaq)m=mtoaDllq$wD'Vu/qw*&yay*&l7!/. C@ DauF!ym=lsmto"!'4"wyu+.tymtu+qwk'D]m/0
` ` `

ymDlnq4umtqwDwyq4wy'4,aqw*&D"y*&l7!/. C
%')rl7"kak']l7!mtoq)m lqeuF'4almGq]mqav 6 qD]mt!+4!+.ltauGompoaq)m
5O"8 wD z}'. 6 C -mpq]D"$nlt*qwDwy!/.Yyza!/uF!ltlpq.p0rs!*q
kj

!+l7".p!mtoaqm 6C oa!+


I XL j T

I 5 8 *&y 5U|8 5 J |8=| 6/+++ 6


j l I I j j nm
L *&y  | wy |  5 |8 wy 5 J |8=| 6+/+F 6
l j j j om j

T 'a.u+qwuFawDqmtD'alq,')(!40
5 8 1 1 wD 1 \ wD c 5 e 8 wD
I j XL
j
\p
j
sj Vj j j Vj X
Vj tj

5 !oaq(!=alt!/vmto"!zUq4um
mtoq)m 64C 8 o"!+0,]$mto"!nlt",al7mtymt mpy'4*&!+mto"' v0
rq

5O"8 5O wD "8FC
&u

5 ! 8 f)XVQ`LI?K"L 5
8 5 twy 5 878FgK"bR[JdXb?d4TUR[?QL/IRK L L/IRQ`Q
I cg

WYQVdLQV[L/MOSQLXNXfL9KRb?MO_;Xf)S fKab?[RXS WsQ4f)SLK L/MOXbX_ MUN


K: ($ & vg 

5 wD 8 %'mtuF!mpoaq)mr=!u+qPk".p""!qwDwmpo"!"a.t!quGoaq,"wy!&"' v !lz}.p'*
0 qavl7mtDwywoaq(4! qv !uFl7D'mt.p!+!z}'4.sq-uF'*&kaq.tlt'lt'.tm C
o"DlsrnDwyw'awy
g

v !uF.p!/qlt! 5 8 qavrnywDw
"'muGoaq"4!mtoa!-!+Vk!/uFmt!vmtD*&!mp'glt'.tmq"a E


z}'.p*.pqav '4* k!+.p*"mpq)mpy'4 5 ltDauF!gmto"!"".p!/q4uGoaq,awy!a'Vv"!/l&v ' m&q !/um


$ < 

mtoa!x.p"""D"mtD*! 8 0"lt'-r=! rnDwDw,!v '"!yzrs!u+quF'4*&k"wy!+mt!xmto"l=k".p',"wD!+*


xw y

z}'.mpo"!k".p""!vmp.t!/! C
Pkaq.tm 5} q 8 0 oaqlwD!/q(!l C o"!+.p!Fz}'4.t!40Y,VPkaq.tm 5} v 8 0 5 8
5 twy 5 878FC
oa!s!+Vk!/uFmt!vmtD*&!Ymp'lt'.tmRq ""yz}'.p*`.pqav '4*k!+.p*"mpq)mpy'4
T   $ & 

'z Dl . 5 .t!quGo"D"mtoq)mwD!/q)z 8 V5 v !/k mtoi'zmtoa!wy!q)z 8C ikq.tm


g

5} q 8 0mpo"!-ka.t'4,aq,"DwDmy94a!/l7mtD'l 6) 5 ltyau+!r=!oaq(4!$'m .pDvi'zmto"!


?z({ @ @n@ A {^| A^}~  T

wD!/q(!lwq,!+wDwy!vrnymtogk".p',aq,"ywDym2 8C o"!/.t!+z}'.p!0]rs!u+qk"awywymn' m=z}.t'4]m


mt'!Fm ~ 5 v"!+k mpoi'zRmto"!wD!/qz 8FC % ')r0ao"')r=!+(4!+.0"mtoa!-lt"*l alm
5 8 0l7'gmtoa!!+ k!umt!v.t"a"yampy*&!l ~ 5 8 ~ 5 twy 5 878
 z { @ @o@ A {| A^} t

5 wD 8 5 wys 85 ,V @ mtD.pwyD" lqk"ka.t' D*&qmtD'0 '. Bz}'4.qwD')rs!/.


$ <   $ &   g

,'"av-l7uGo-qlmtoaDl
'4"! ,Vmto"!!+wD!+*&!/4mGq.pu+qwuFawDqmtD'lto"')rnD-u+wDq4ltl 8C
g g w

5 z 8I?XV LI?K"L_hXafK"bf)K"bR[RXSMON/QV[BdXSPW
K f)MUNXb NXafL RL/IRQ]fQQ

MUN/L/N-K[RQ4LQ]fSMUbRMUN/L/MUdd4XSWRK f)MON/XbNXafL N?dIBL/IRK LRXbBK4Q]f)K"Q


' 

L/IRQ`bRSZYQ]f\X_d4XSWRK f)MON/Xb?NWYQ]f)_hXaf)SQV[^Z XbKRb?MO_hXaf)S


f)K"bR[?XS WYQ]f)S9?L/K"L/MUXbX_ MUNb?X f)Q]K"L/Q]fL/IRK"bLI?QbRS9ZYQ]fX_
dXSPW
K f)MUNXbRNeWYQ]f)_hXaf)SQV[ Z !rnDwyw lto"')ro"')rcmp'P!+m.tvB'z
'a!.Gqav '4*&Dlt!+."' v !rnmpo"' mDauF.p!/q4l7D"mpo"!q(!/.pq!V"*,!+.'zsuF'4* E
u

kaq.tl7'4alRk!/.7z}'4.t*&!v-,V$'4".Yu+'*&kaq.pl7'4-lt'.tm C !/.7z}'4.t*&D"xmto"l'4k!/.pqmtD'
.p!+k!/q)mp!/v wDrnywDw4VD!+wvq v !+mt!/.t*&D"Dl7mtuYu+'*&kaq.tl7'4l7'4.7m C?@ "k"k'4lt!Y'4"..Gq E
~

v '4*lt!+."' v !suGo"'V'4lt!/l""yz}'.p*&wy.Gqav '4*&wyq*&'" lt", mt.p!+!l ~ /+/F )C


o"!/mtoa!9!+Vk!/uFmt!v.p"""D"mpy*&!e'z$'4".uF'*&kaq.tlt'lt'.tmg'4q"a E
 5

z}'.p*.pqav '* k!/.t*- mpqmtD'\'z$ l . 5 .p!/q4uGo"yampoaq)mwD!/qz 8


5 v"!+k mpo'z?mpo"!wD!/q)z 8FC9< !+m l$,".p!/qmpo"llt"*"kD4mp'imtoa'4lt!wD!/q(!lrno"uGo
Kz({ @ @o@ A { | ^A }N~ %

q.p!yPlt'*&!mt.p!+! 0Rqav9mtoa'4lt!rnoaDuGoeq.p!&"'m C@ yuF!&mtoa!l7!uF'v9lt"*


w
 R

rnDwyw?"'mxuGoq"4!rno"!+r=!!+m .pDv'zmto"!$.Gqv '*&l7!/."' v !0rs!y4"'.p!m


z}'.$mto"!g*'4*&!+]m CP5U ')rs!/(!/./0Rv ' m$z}'4.t4!Fm$ym 9r=! wywY.t!+z}!+.$mp'ym-l7!/(!/.pqw
kaq.pq.Gqk"oalY,!/wy')r C 8-< !Fm ,!mto"!v !/k mto'z?mto"!.Gqav '4*&Dlt!+.="' v !0"qav
w ? ow

mtoa!k".t'4,aq,aywDm'zR.p!/q4uGo"D"mpo"!.Gqav '4*&Dlt!+."' v ! C
I

%')rwy!+m lnwy'V'4q)m q " !/vgwy!q)zRyilt'*&! mp.t!/! tC  !/"'mp!,V mtoa!!+(!/]m


'zR.t!quGo"D"-mto"!.Gqv '*&l7!/.=a'Vv"!$qavuGo"'V'4ltyalt", mp.t!/! |pC o"!/
w  3R R

. 5 .p!/quGoay"-mtoq)mwD!/q)z 8 . 5 .p!/q4uGo"yampo"!.pqav '4*lt!+."' v ! 8


~ ~
. 5 uGo"'V'4lty"lt", mp.t!/! .p!/q4uGo"yampo"!.pqav '4*lt!+."' v ! 8
~  R

. 5 .t!quGo"D"-mtoaqmwy!q)z 8F
~ R

'mpo"!+.Yrs'4.pv"l/04ltDauF!nmpo"! lt", mp.t!/!DlY""yz}'.p*&wy.pqav '4*wD-uGoa'4lt!+q*&'4"


-uGoa'uF!/l'4auF!r=!oaq(!.t!quGo"!vmpo"!.Gqav '4*&Dlt!+.="' v !0

~. 5 .t!quGo"D"mtoq)mwD!/q)z 8 6 . 5 .t!quGo"D"mtoaqmwy!q)z ;8+


f ~ R

%'mtuF!mtoq)m

5. .p!/q4uGo"yampoaq)mwD!/qz 8 . 5 .t!quGo"D"-mtoaqmwy!q)z0al7mpq.7mpy"Dgmp.t!/! 8
~ R ~  R

RyqwDwy40 "'mpDu+!mtoaqm

v !/k mtoi'zmtoa!wy!q)z 5 v !+k mpo'zRmto"!wD!/qz?Dgmp.t!/! 8  R I


oVal=mtoa! a.pl7ml7a* 5 ')(4!+.wD!/q(!l='Vu/uF".p.py"Dlt'*&!mt.p!+! 8 ,!/u+'*&!/l
  R


?~

R

@ A {^| ^A }F ]
~ . 5 .t!quGo"D"-mtoaqmwy!q)z0al7mpq.7mpya-Dmt.p!+! 8 t5 v !+k mpoi'z?mto"!wD!/qzRDmt.p!+! 8
 R o  R I

@ DauF!mto"! lt"*'zqwDw mpo"!k".p',aq,"DwyymtD!/lD&mtoa! D""!+.sl7"*l 6 04rs!xu+q&k"awyw


'"m mt'!+m I

6
. 5 .t!quGo"D"mtoq)mnwy!q)z0al7mpq.7mpyaDmt.p!+! O8+5 v !/k mtoi'zmtoa!wy!q)z
ymt.p!+! O8
?~
 p ~ R R In
R0 @ A ^{ | ^A }F ] q

%')rwy!+m ,!mpo"!()qwD"!'z | rnoaDuGo*q4!/lsmto"!D""!/.l7"* 5 ')(!/.wy!q(!/lsD


8 lt*&qwywD!/l7m C5U o"!/.t!*&y4o]m,!l7!/(!/.pqwRuGo"'4Du+!/l *q!&qVi'4"! C 8P o"!/
mtoa!$l7"*q,')(!Dlnqmwy!ql7m
 R U

p
@ A {^| A^}=F ]
~ . 5 .t!quGo"D"-mtoaqmwy!q)z0al7mpq.7mpy"Dgmp.t!/! +8+5 v !/k mtoi'zmpo"!wy!q)z
ymp.t!/! 8
 
q
Io



^
{ |

@ A ^A }=F ]9
~ . 5 .p!/q4uGo"yampoaq)mwD!/qz0"lmGq.tmtD"&ymt.p!+! 8F5 v !+k"mtoi'z?mto"!wD!/qzRDmt.p!+! 8
 

%')ro"!/.t! lmto"!-mt.puG zr=! mto"!-.pqav '*&l7!/."' v !40rnymtoqwDwympl


>^= o
lt", mt.p!+!l+04,Vmpo"!xlt", mp.t!/! 0]mpo"!+'4"! u/quGo"!uG$mtoq)msa')rmpo"! !+Vk!/uFmt!v
w

.p"""D"mtD*&!'z='4".qwD'4.tymtoa* 'qa"z}'4.t* .Gqav '4* k!+.p* mGq)mpy'4P'z




l !4qw?mt'mpo"!,"yl7a*J'impo"!wql7mxwDya!-'zmto"!k".p!+(Vy'4alkq.Gq.Gqkao0
k"wDalnmpo"! pl7!uF'4avl7"* 5 mto"!'a!$')(!/.nwy!q(!/l"'mylt'*&! 0rno"uGor=!
oaq(4!-lt'zUq.,!+!/D"'4.tD" 8FC$ ')r=!+(4!+.0,Vmtoa!rqrs!&uGo"'kl7! q,')(!40
) ' R

mtoaDllx4aq.Gq]mp!+!/vmp'g,!&"'4.t!q)mp!+.xmtoaqmtoa!q(4!+.Gq!.p""ay"gmtD*&!&'z
mtoa!'.py4yaqwqwD'.pymto"* 5 rnmpoP.pqav '*&l7!/.yek"wqu+! 8C oaDll al7mrnoaqm
rqlv !/ltD.t!v C
X

 
 "!$#%&('*)!,+$-!/.0 #1132
465784:9<;>=(?@BA # 7$CED>FGFIHJKL,MGN L8OPKQMGNSRKTN"UVN WW*NSXYHZ\[^]>N LNTW*K`_HW*]>JaL,H
J,HWLbcN"UG]dLM>N LeL,MGKfK3X^HZK`N"_MdW*K`_HW*]YMGN"JgLM>KR"N"hiD>K 1 HW5SjkU
N"hmlHWnmL,MGopZqHrWJHrWLnmUGltsuL,MGKfK3XEJaHZ*vgJD>_MVNJK3LaHZW*K3_SHrW*]GJwonmlML
FIHJ,JK`J,JJ,HoKxHZyL,MGKgZqHhihmH`OznmUGleLM{W*K`Kg]GK`J,nmWN"|GhiK}_MGN W*N"_L,K3W*nmJ,L,nm_SJ~
 jL,MGK}N"hilHW*nL,MGoW*DGU>JzniU\4m[{7L,nioK
jL,MGK}N"hilHW*nL,MGoniJJ,L,N"|GhiK
jL,MGK}N"hilHW*nL,MGoJHrWLJniUFGhiN"_Kj
4iS7}nRKN"U}N"hilHW*nL,MGoL,MGN LMGN"Jy_MGN W*N"_L,K3W*nmJ,L,nm_SJ  N"UG] j>E{E>3
u -"! Br . y }\4m[{7 +\!
4 - 7gnRKwN"UNrhmlHrW*nLM>oLM>N LM>NrJ_MGN W*N"_BLKSW*niJ/Lnm_J  N"UG] j$y (
? .!,')-"!/.!/ + 5 !,' ' ! !/ +' #" ' ! r EG>SG $ 3{ "-r.'S !0
.  Q\4[{7 +\! Br  ! \4u57 +\!,+'S.S0 '.  ..
' !c! . ! y ' ' u ') "!
4 7}nRKN"U}N"hilHW*nL,MGoL,MGN LMGN"Jy_MGN W*N"_L,K3W*nmJ,L,nm_SJ N"UG] j{,"3{{3
u -"! Br '. < !
4 # 784:9<;>=(?@*AS7
4iS7}C{M>H`OL,MGN LSbGlnRK3U # []GnmJ,L,niU>_LPUDGoe|IK3W*JSbEL,MGK3WKxN W*K:y FIHJJ,nm|GhiK
O$NSXEJcL,Hx]GnREnm]GKL,MGK`onmULHLO$H}JHWLK`]aN"WW*NSXEJbEK`N"_MOznmL,Ma[eUDGow
|IK3W*Jj &(' !  ( ! ! . -! g ' ( !/*z + '`' "
[ r+$-!/.
.'S+ ! # [ '. r "+P-!,. >  !/! 0'S-3) ' ! '
! . -! )'S)S! '`' 6 "[ r+$-!/.
P 0 ! [x "+$-!/. -!/' " r
' !. 6 ..  !' !/. rB 0 ! ! /  P '`' 6 "}[
"+$-!/.
I '`' " !! . ! '  !. 6 .. S0 ! !  )! .! 
' ! !! . ! '  ! ! ' r\ .. 4  6 ! .!,+ r[ "+P-!,. 7 0
B !,.! '3"! u ' ' '. !,. "g4 ! ! .. .! '. ! 0 r
' x 6 ! . ! 7 < ! ' 0 !/.! .! < ' '`' !
[e "+P-!,. < .'+ '`'' # [8 6 "+P-!,.
4 - 7xJ,niU>lxNx]>K`_SnmJnmHU8L,W*K3KbEJM>H`OL,MGN LN"UXwN"hmlHrW*nmL,MGoL,MGN L_HWW*K3_L,hmX
oK3W*lK`JLO$HJHrWL,K`]ghinmJ,L,JyDGJ,K`JN LhiK3NrJ/L # [c 4[{7>_HoF
N W*nmJHUGJjy !
'. r `)!,. ' '  .'-"!/+ { I6 !0S-" I 'r r )S!0 
+ B 'S+ . ' .! ! 8e $I* < */ ' -"! ' ! .
! !/. 'S+ . '  !I-! 6G !{r'.{!/ + !0 '+ . ' '
 ! [ ! .$'  !. 6 .. + !/. rB !r. 6 !/!/+\! '
! ! '  .. 0 ! x ' ". !/. '+ . ' .! ! ! . '+\!,. !
! u ' ..
a! ' !,. ! / ' .!/!P' !$  '. 0 g ' A ! ' ! *A
-!/! -` '+ . ' 0 !<! r r  , ! 6 " '+ . '
B !.  >  "B   , ! 6 "3' !S*-" ' a ! -!/ !
! )! -` ! ! '  r ! I ! '. ! P .. '  !! . ! '  !r. 6
..  4 "'.<! + !S0 'r. .. !,.!$i%"2 3 B i#" @ 5 130 ! !
'. !  .. 'S" -!\:# %"2" @ " 5 130 !c! . ! ' > !r. 6
.. .! ! ! ' r 0 . r ' !( -!/' !! E ! '"
.! # %"2 SG&' ! r < ! .!' ' !,. ! !/ 0 ' !
-!/ '" w $ !,-! 2 # %"S 7? ! !/.! .! y ' 6 -"! -!,
4 ' ! '.! $[A !/!/+\! r- ! ' { 5 ,//# [ 7 0 r !,)!/. ' 6 -"! -!/


+$ u ' / ".' w ! 6 ' !z.! r -r!! 0 !g . ! { ! 6 ' .!,!
4 a ' A .! r -"! ' ! .!\.!,+\'*)! 7( ! u .! "A
-r!z! )S! ? ! 4 -  . 7 .!,!z' !  P  +\' 6 # ' ! 0
! r )S!  y ! ! S ' { ! ! 6 ' .!/! ! 6 ' y ? !
! ! S ' ! ! 6 ' .!,! ! +\! ! '. u A ! r+$-!/.<'
'S+ . ' 0 ! 'r ! ' '  r ' < # [w 4[{7
y !,+ " ' . !' ' 4 # [{7S #
' [rr . ' !
! `+ ' c '.+$" ' d 4 ' 7 0-" '`! E '. 0
'. ! '' " .! ' yr '  4 ' 7 +\!  r < !/.!
.! ' 6 B  r  ' ' 4 7 '
'.  / ! . !<.! / r -3 + !/. ' 6 B  r
-` . !/.\' ! ! ! .S0 !+ "+\! r z ! !S
 ' $ '.  1"0 -" 5 80 &( '. + ! ' ! . 1 ' ' .'-"!/5 + 0'" .
5 0

!
' 
4 7
!, 3 !/)S! ' < 'S. 5 y  ! rE )S! ' 4 # [{7S #
' [ 
4 # [{7 ' 4 # [{7 # [ ' 4m[{ 7 # [} # 4 7[ ' [  )S! I !
rS 5 0 !!/..'. !,.+ 'r -!  4m[{7 0 ' 4[{7
I ' 6 -"! ' '  ! ! .! .! "  " ! " '. !' ? . "
r .' + ' g4 u !  '  uy ' !,3"! !+! ' !  -'*)! 7 0`-"
 B !/
c' ' .'*) ! ! '' " + !,. . r+!
!(- ' A
+ !,'.!/+x0
 # [  # [ 5 5  4u5T57
 
  
 + ! " ' ' r :   4 # #[ 5 #  7
   " ! 

. r .,0 :   1 $ [ 0 r i  1 $ Q[
y +\! B < r V 0  1",//,# [ y 
4 # %[ T57  # [ [    #  [  #

'' :y  # [e ' 4 # &[ 57 ? !z' 4 # '[  57 4[{7 0 ! .!
!
4 7}C{M>H`OYL,MGN LbnmZ{LOPHK`hmK`oK`UL,JyN W*K_HU>JK`_D>L,nmRKnmU}LM>KJ,HWL,K`]gHW*]>K3W
N"UG]8_SHo K$Z:W*Ho HF>FIHJnL,KPN WW*NXEJSbL,MGK`UgL,MGK3Xgo8DGJ,L|IK\_HoFGN"WK`]j
?  ' ! r ( !P'. r .. .!) ( /,/,* ( B ) + /,/, + r
 r ( r +.- .! ' !  )! ! 'S . ! 'S. !/.$< 6 " !
.. c ! ! .0 !+  " ' !  ( +*- ?  " ' !  '
'S+ . ' +  !-! u !,! ( r +*- ? ! '+ . "P !, !,+\! 0
' !/ . rB ( 'S./+*-B0 '0+*- \ ! +\! z 'S+ . r z '1( 4 6 !
( Br +*- .! ' !  )S! 7 0 r + . 'S. '+ . " !,!,+\! 0
' !/. r ( 'S.2+*-B0 '3( 0 ! '' ! +\! .' S ! ! / A
' .!,!0 r8 ! !z.! ! +\! ' !0 < !\. 4'S ".+\!/. " A
'S. +' ! u  ' 4 '. ! r7 .. ) ( /,/. (  , + - * ( ,///* ( r
) + /,/, + - * ( . + - /,/, + y < r )S! !6! 5! ' > " (
B + -  !$'S  0 ) r B 'S..! '. ! } .. S ? !
' .  ' 0 !/.!+P u !,. r )!-!/! '+\! 'S+ . ' +  !
-! u !/! ( Br + -
7
4ir7xJ,KdXHD{W N"UGJ/OPKSWL,H 4 # 7wL,HJ,MGH`O LM>N"LbgnmU L,MGKdO$HW*J/L_N"JKb
# [}5_HoF
N W*nmJHUGJoaD>J,L|IKwoNr]>K8OzM>K`UoK3WlnmUGlLO$HJHrWLK3]
N WW*NXEJSbK`N"_MQ_SHULN"nmUGnmUGla[K`UL/W*nmK`JSj9 ' 6 !,. ! u ' 'S. !  ..
m1r#"//,# [ #S r 5 %",//# [5 y ! xB u ' ' !  )!! A
. ! c ! '. ! 8 .. 'S+! .'+ ' " ' ! .. ? ! !/.! .!
# [z5  . 4 ! : Be4  57 6 0 'S.  1r//,# [z57 0 ! 6
# [5 '+ . ' +$ 6 -!+ S !
4 % 784:9<;>=(?c@ 8 A # 7:9 M>N"LyniJILM>KcOPHrW*J,L_SN"JKW*D>UGU>niU>lLnmoKZqHrW<;c{G >S>=
9 M>N LJnmoFGhiK _MGN"U>lKLHL,MGKN"hmlHWnmL,MGo FGWK`JK3WRK`JnL,JhinmUGK`N W@K ?FIK`_BL,K`]
W*D>UGU>niU>leL,nioKN"UG] o N fK`J$nmL,JOPHrW*J,L_SN"JKW*DGU>UGnmUGlgLnmoK\4[ ' I[{.7 =
!! . ! '$' !(-" ! 0 ! A ;c{G >3 4m 6 ! .'+ 4[{7
'*)!,. ! r7  6 >/"3>>3 ? ! ! ' ! 'S. 6 A !. r r
+\!' >/"3>>3 4[ 7 0 +\!  <  ! 'S. 6 A ! . r r
+\!' ;c{>"{3 C B 4[ 7 8!' B 4[ 7 0
. !/. B 4[ 7 0
-!  ! ! ' E '  !.! ' 6 ! . !/. r ! ! !/.!
E! . ! < ' 6 " !c-" !  ! '. 6 !
y ! 'S' r .!,+ . '+\! }rB E D G F8 ' r' y  '
' I H 1r J7   # F 4 1 7 1 B FE K K M4 L7  1 '. L  1"0 ! F N4 L$7 
F M4 O" 7
TVU F 4ML 7
F M4 L%PFO"7 TW ' .U L L OR'. QSH 1r JL 7 //,y L !  0E1r-` r  ' 0 !  )! r
8  ! '  .'S+   4 !/! ' Y5 X 2\'
U ! ! 7 r ( !$. " " +!
' ;c{> {3 ' wB  ' ! " w[ 4[{$7  T    \4 7 0 !/.!
" I! ! ! " +$ ] -!/\.< ' ^ ! I . ! ! I +\!S ! ? !  < Z ! H4 '  e6 5*7 [[  .[! [{7G B! r +\ !!0 ' ! 6r  )S !
r
   
\4 7 6a

` _


? ! F D L3bcdL r! G ! ' r ' '  ! .!/) ' .  . 0 ! r )S!
r
 
_   [
a

y  !. r r +\ ! 4[{e7  \4[ 7 \4m[ 7 R fI 6 r $ ' ! !/.


! .!/) 'S -'S r 0 ! r )S! r ! '. 6 A !g. " " +\!'
;c{> {3 4m[ 7
?  " ' ! r ( !.! ! ! y ' {,"3>{3Q4 ' ! -" ! 7
h' g "{ >S 03'S.  P' !,. u 'S. r$ 'S. +x y ! !
+\!.! ' " y y ' < r !. " " +\!-! 'S+\!
4 m[{7    \4 ' 7  4[{7 Q   '

 
 ' '  -'*)S! ? ! \ 4 ' 7 \4 7 0 ! 6 r )! r
 
kjmlYnYo"o"n@pr! qY.su tu" vC "w xz y|{% }+\~,! lYn2 "lY4m)[{nY7 o"i)TYo$4 YlY |\4 l u 7 0 @' G ! tzu}h r4 )S}! h @4 tY}N}  !(lY!/" oG @! tz }!
"lY)|~,l6pYonYo"| ,~.| o~.2/x>Y)4tY},YN4}:6lY"o>r ro"o"N>Yo"|o) | op,oY~oE)r~.
YrlY"|o~,|lYYp.|krM4tz},erM4}/xz6lY"o
|z|)Yo
4~,%xzp,u@ GtY}.G@4},e4tz}@
~lYlYnzo")o*~,)lYe Ylz")l@6Y*p4
~,l/xzp4utY}@ }4tz}>/@x@<tz}u@ x}u@ tz}&xz

. " " +\! \4m[{7  !}' !,. rB 0 ' ! r \ !  ' F '
H 1r J7y ! ! `-
L L L 1
F N4 L7
1r L 1 

! < ! '  ' ' G ! . B .  -'*)!S0 ' 


    a  a [ ' [

'
 _
' _

 
y  y ! 4 '. u A ! 7 . r r +! 4m[{>7  \4m[ ' I[{7 \4[ ' I[{7 8!
 ' -'*)S!  xx ' B 4[ ' [{7 0 ! ! r  ! '. 6 A !
. " " +\! '. +\' r! )S!/. 6 ' ' ;c{G  >3 4[ ' [{7
4 8 784:9<;>=(?@ 8 A 8
7 9dK$N W*KPlnmRK`U}[xU>HU SK3WHFIHniUL,kJ N4 L O 7bE5  [brnmU
L,MGKDGUGnL$]GnmJ,fjC{D>F>FIHJKL,MGN LPL,MGKFIHnmULJN W*KD>UGnmZqHWo hXw]>niJ/L,Wnm|GD>L,K`]b
nujKjib>LM>N"LzL,MGKgFGWH|
N |GnihmnmLXHZ GUG]GnmUGlN"UIX ?EK`]FIHnmULzniUNJ,D>|GJK3LHZ
L,MGKg]GnmJ,fnmJFGW*HrFIHWL,niHUGN"hL,HaL,MGKgN W*K`NwHZyLM>N LJD>|GJK3Lj
CED>FGFIHJK N"hiJ,HtL,MGN LLM>K FHniUL,JN W*KdniU>]GK3FIK`U>]GK`UL,hX]>niJ/L,Wnm|GD>L,K`]b
L,MGN L niJbL,MGN LLM>KPF>W*H|GN"|GnihmnLXgH>Z
UG]>niU>lJHoKJD{|
J,K3LHZGL,MGK$FIHnmULJnmU
NgJD{|
J,K3LHZLM>K]>niJ/fwnmJL,MGKFGW*HE]>DG_BLPHZL,MGKniU>]GnREni]>DGN"h
FGW*Hr|
N |
nmhmnmL,niK3JSj
"s MGN LJK`UL,K`U>_SKg]GHEK`J, U LN F>FK3N"WnmUQLM>K}L@K ?Lb
|GD>LznL\J,MGHD>hi] v
K `JnmlUN"UQN"hmlHWnmL,MGo OznmL,MQhmnmUGK`N WP@K ?FIK`_L,K`] W*DGU>UGnmUGlgLnmoKL,HaJ,HWL
L,MGK [FIHnmULJ}|X L,MGK3nmW8 ]GnmJ,L,N" UG_K`JgZ:W*Ho LM>KQHr W*nil niUIj}y ! ! ' A
 ! ! .'*) '  L 1O  1 4 !S0 r L O  m1r1S 7 0"-r ( (
 " ! ! . 9 ' 6 !/. ! '' "} '. +x\r'. ' )! ! !S0 !  A
.' . ! 8 r L O ! ' [ ! r' #" .! au! '.! w.! B .! . 3' \ r ! . ! ' . ' 0 B r 
' ' B '. " ' !/+xc8! 6  !, ) "! ! '. +x0
' ! ' !  'S. r
= !/+\!,+$-!/. .'S+ T r ! r )!  ' ! !  )! '. +
{/rSN4 (6*  7 0 !/. ) "! (@ I r!( ! r ' ! 4 . $! r7
: .' ' u ' A +\! 6 '  .. 10 Br>{ " {4 [{7 0
.!  ' 5 ! [ r! ! . ! ' u ' A +\! ' r .. 1 ' r !
'  .. z' ! " [

3`* ;c{G >SI4 7
5a&[ ! " > H 2
# .! ! H 1/, [ H5 // [ e  u ' A +\! 6 '  :0 4m/[ 57 [ 0 .. 
% ZqHrW 5 ' [
8 r- - H5 ' - H r#
2 6 r- h' H < !/
{,"3
4 H :. @ [ Y- 7
X K`U>]GZqHrW
@QZqHrW  5 ' [
H  {,"3>{34 H  7 ? '. ! : .' ' c ! u ' A
+\! ' r .. h 0" 6 " #! - y !,
5 1 K`U>]GZqHrW
55aW*K3L,D>WU{{ " {4 [{7
&' ! ! ' ' !/! ' '. H r1 q0"-!  ! ' 6u ' ' !
+\! 6  ! 4 1 7 .'S+ !'.

".. 6 6 y ' S ! ' I ' !' [ - -" ! 0 !/.!
- P ! .' 5!/. .'S+ !h 6 ! ! !  c !
-" ! .! ' ! ! ! r ' -!' !,3 4 ! 4 !0 '.>! + !0 ! Br r
-

' c r !/..   1 [[Br 'S !,.z. S  5Y[*[ + x ! .!


.!,+\'*)! +P + !/. B ! " " '
" !/..   4[Q57*[*[8r
' !/. . S  [ [[ . ! " " ! . !$! !' ! 7 0 !$'S. r
u !/+\! !/.! r ( !$!/ ! ! . " " +\! 4m[ 7 ( '..! y
'S. + r !/ ! ! . " " +\! 4m[{ 7 y !,:
y !.! ' 'S". .' '. ` r ! B" " ' 6 " ' '
' !6rB, 6  " ! .'+ !'S. y w44  57*[*[  [[ r )S! ! +\!
.! '.  5 /,/ [Y4 !/.! P 'S"  ' -! ."! !.!/+\'*)S!
! 'S. S .! 7  $ !'. r . ;c{G >3 0 ! !/! r P !
! ! ! . " " +\!<' 
S`. ;>G >3 4m[{7  T \N4 %H 7 0
!/.! I ! 4 !(' { ! i -" ! Br ! " ! ' u B I ! 1 \ ^
! +!S ; ! G - -! ! r 'S.. r 'S+d ) . -"! 5 - Br
! : -" ! 0 Br 1' !,. ! y ! T - - P&(' !  c !

-S0
5 /,/ [ 0 .! r ! ! r ! . r '+ ) . -"!  'r0
%H - f. 4 -
57 f. 4 - r y -r ! u  7
- ' ! ! ' y 3 .!
fI. 4 .   4  5*7 [*[ -" > 6 ! ! 6 7
' G S .! . S   [*[
< ! ! ' '  '.+. B '+ 6 . -r ' 0 u !
5 4i .! ' ' !/. w .! '
" !/. 6 7
4 ! 'S.I' r5 [ .' -!  ! ! ' .! 0 ' 5 0 r ! !/!
' '.+ ! .'- - ! 7 ? ! ! .! '  +! ( S .!
. S  0 ! .'- -  u
4 3 .! 'S !,.. S  3 .! r !/..   7 [ 5
y  ! !(. B '+t) . -"! e - .! ! +\! I ! ' ! r ' , "..!
4 !' ! !/ ! ' Y5 X 2<' ! ! 7 0 Br ! " ' .' !/!
-! '.! ' '  
!!/ ! ! . r r +\! 4[{7 [4 # Y5 [* [{7  4m[{7
4 2 784:9<;>=(? # X 5A # 7CED>F>FHJKaL,MGN Lx[TnmJxNFIH`OPKSW8HZ # jaCEMGH`OMGH`OL,H_HUE
J/L,W*D>_LwNrUY[nmU>FGD>Lb[HD>L/F
D{Lw_HoF
N W*nmJHUYU>K3LO$HWfYHZz]GK3F>LM ' [
nmUOzM>ni_ML,MGKaL,HFHD>L/F
D{LO\nmW*K8N"hmO$NSXEJ_SN WW*nmK`JL,MGKao nmUGnmoaD>oniU{F
D>L
R"N"hmDGK NrU>]dL,MGK|IHL/L,Ho HD>L/F
D{L}OznW*KN"hO$NSXEJe_SN WW*nmK`J}L,MGK o N ?EnmoaD>o
nmU>FGD>LR"N"hiD>Kj 8! ' 6 . 0-` r  ' ' ' [ 0 '+ . ' P ! A
'S. g g  H [  ! ! .! .' !/. ! 0 Br   r P !
' +\' 6 'S  .! r ! ' [ 4myr 0 ! .! ! "z '  u
!\+ +$"+ ! '  '  .!S0E-" c ! .!P' ' / ". 7
g g  H5 -! !} 3"! '+ . '  ! u 'S. ' [ 5 .! 
g g  H [ [ r# r -!/! ' u . ! 0 ! R! g g  H [ '-! ! 'S+ A
. ' } ! u '. . 6 ! ! ' B -' 6 '+ [ [ # .! .' S
u ' ' ! ' g g > H [ [ Y# <. r r . !,i0 ! ! c ! 5 6 r
e lYnY~.)|~,lYnYP,~,|~,Yo"pz)Y
NY)>o~,lY)r~.)Yoeool)|zo" lYnY~.)o~,|oelYnYo"o"lz
nYo"l6:>zo$lz|o"zolzoe4>z)r~.kw , 46 Auw w 4

4[ [ # 57 u 0 Br ! 4[[ # 7 Pr[ 0 .! { .' S u ' 'S+ . 'S. ? !
! u ' ' ! ' g g  H [[ #r3. . !,i0 ' ! u ' ! '+ . BA
'S. 0 ! ! ' g g  H [ '\+\'.! rB ' 4[[ # 75 ' [
!' !/. rB 0 6 ! ! ' '  < .!(' ! ' ' P' g g  H [[ #Y
r ! ' 4[ [ # 7 0 r ! ! ( .'  ' !P+\'S.! '+ . 'S.
g g  H [ :0 ! ! ' ! ' '  z .!' g g  H [ !/
' 4[ [ # 7 Y5 ' 4[{7 0 ' ! ! ' g g > H [ ! 6 ' [
y  y ! ! ' { ! ! u 'S. .! / !/' [
&' ! ' r ! '+ . ' P ! u '.  !+ +P"+ Br + A
+P"+! . ! y !/.! ! B y !,+  !/! 0 ! ' ' ' g g  H [ [ Y#
r ! !+ +$"+ +\' " ! r. u 4[ [ # 7 ! . ! ' ! 5 uy .!0 r
! - ' 6 '+ ' ' g g  H [[ #Y  ! !(+ +$"+ +\' " !( 6
4[ [ # 7 ! . ! ' ! 4m[ [ #  57 6 .! y  c !+ +$"+ +\' "} !
! . ! ' ! 5 6 '. 4m[ [ # 857 6 .!0 ' ! 'S+ . '. ' " ! " ! !
u ' .! +\'*)! !+ +$"+ ' ! 5 u 'S  $ .!S ? + ..! ' "
' < r !+ +$"+ ' ! [ 'S  .!
4iS784:9<;>=(? # X 5A 8 /7 cWH`RKdLM>N"LTN"UX J,HWL,nmUGl UGKSLO$HWf HU[nmU>FGD>L,JMGN"J
]>K3FGL,MaN L hiK`N"J/L ' [j? !/)!,. !/' ! .'*)! r 'S+ . ' $ ! u '. '
! & \r +\' 6 4[ [ # 7 '+ . 'S. 4 ! !/.! B -! +\' 6 4m[ [ # 7
6 +$r B !,' ' A 'S+ ! " 'S+ . ' 7 r 'S+ . ' c ! u 'S.
'S+ . '. B -! ' )!,. ! ' 4 !,. 7 'S+ . ' '. E '. [A !,!,+!
 $ + ! $ '+ . ' ! '. u !S r ! '. 6 A !
"+$-!/.P' '+ . ' '   'S. B 4m[ ' I[{7 B r $ !,.! '.!
4m[[ # 7 B 4[ ' [{7 0 ' B 4 ' [{7 y  !,. ! 'S..! 0y-"
'`! E
' a !! .! " {  % ' [ 4 ! )S! ' ! ! ' 6 - 0
'.!/ + !S0  7 ' [Rh ' [ 7
' ! ! ! .! " 0 !  ! ? . rr .' + ' 0
[ # [ 46S5  46Y5 [*[{767 0 ! ! !,. 'S.+ [ 4m[ [r*r7 y 
' [ [ ' [a[ ' _ [ # ' [ # _ 5 ' ' [
aA a
4B7

[  # 0 ! 0 6 ! 80 ! r )! [  ' .., Brd|4 B7
' r ' [k  ' [ [ 5 0{' !z)!,. r! ! r ' [
1 ' [ y  0.! ' " ( ! .!/) ' . B . 0 ! r )! r
4m [ [ # 7  ' [  4[ [ # 7 ' [ 0 ! ! r % ' [ 0 'S. [
4XB784:9<;>=(? # X # A # 7 cWH`RKL,MGN L N}_HoF
N W*nmJHUwUGKSLO$HWfwO\nmL,M[wnmU>F
D{LJ_HW,
W*K3_L,hmXJHWLJzL,MGKanmU>FGD>LN WW*NX [ [x5 ,///# 5 niZ(N"UG]HU>hmXQniZ(nmL_HW,
W*K3_L,hmX8JHrWL,J L,MGK}4[57 K3W*H"HUGK\J,K DGK3UG_K`J 5 1r//,13 b 5 5 1",//1S b
5 //,/ 5 13 s6nujKjibLM>KJ,K DGK`U>_SK3J_SHUGJnmJ,L,nmUGlHZ  5 JZqHhmhiH`O$K`]8|X4[$  7
1 JbcZqHrW  5 # ,// [85v*j y ! .'S-"!/+ 'S. r . 6 !  !,.! A
'S..!  ! [ !,.' A ' ! !Sr! !0 5 //, 5 0y-" 0 6 !}!/)!,.
'S+ . ' ! u '. '. ( !,3"! ! '..! 4 !P' ! ' 6 -"!' 
! '..! ' ! 7 0  " '.!  " + ! ' 5!, .! !S
"'S.  5  [ 0 ' !,. !+\' ' ' .! "  ' F
)! -`

F 4ML7
1" L [x 
5 L  [x 


< ; !/+\+ # X 54  r 0 " ! .  6 '.+ !  > .! -` +' ' A
' .! "  ' }  e F x ! ! . B 6 '.+ !\' 
.! < ! +\! 7 0 [ ,/, [  5 [z  , /// 5 'S. ! '..! S0
! ' F 4m[{7 /,/, F 4[  57 F 4m[  7 ,//, F 4u57 5 ,/, 5 1",/,13
4m !,3"! !  5S 0 '' ! -` 4m[  7 1 7\y y !\ ' rr '
!\ r ' 6 !/+\!
&' ! ' !/. !e r < ' . ' 6 ' 0 z  ! P ' .'*)!D
[ [w 5 /,/ 5 1S  '..! '. ! 0 ! ' ' !' ( ! !,. ' A ' !
!3"! ! +\! ' ! \ -'*)!SE r !,! 0 [ [ 5 ,/, 5
'S..! 'S. ! 0
! !,.! .! 5  [  r y !'S  y .! .. "2 -'*)S !
!P'  .! .. r  &('  ' !/. .  6 '.+ " !  -3 F  
y !  -! '+\! ' !c' G ! !/.' A ' ! !,3"! ! 3"! u ' 0 !/.! < !
'  ' r F  44 `7 5}4 !   [g4m[e  767 ' a .! -'*)S!
4  7 1 4 !   [4[x  767  ' !/)!,.,0 'S..! 'S. ! 0
  ! 6 .!
F

4i@S784:9<;>=(? # X 2 A % 7CED>FGFIHJKaL,MGN L}O$KMGNRK N"UdN WWNSX HZhiK`U>lL,M # [O\MGnm_M


O$K OznmJML,HVF
N WL,nmL,niHU niUL,H nLJQ[JoN"hmhiK`J/L NrU>] [ hmN W*lK`J/LK`UL/W*nmK`JSj
cW*H`RKwL,MGN LO$Kw_N"U]>HL,MGnmJnmU_HU>J,L,N"ULN"]G]>nmL,nmHUGN"hL,nioKeNrZiLK33 W GW*J/L
J,HWL,niU>lzLM>#K >W*J,L[brN"UG]gLM>KPhmN"J,L[brK`UL/W*nmK`JSj a! + r '+ . '
! u '. z r < ! ! 6 .! !65! ' . ' > '. ! !,.' A ' ! !,3"! ! 0
r I ! ! 6 .! ! 5! I '. : . ' E '. ! !Sr! !    i0 <  !
' .'*)! ! ' . ' )S! y  0  " ' ! r '". '+ . ' 8 ! u 'S.
'`! '  'S..! +\!/. !N ( ,/,/* ( . + //,. + 4 !/.!N ( ,//,* (
Br |+ ,//,.+  .! 'S. ! r7 y ! !/.! .! ! . ! u S .'+ ! 
  !'  .! .. " -'*)! !\'  c .! .. "
4my G 'S ' ! 'S. r 0 '..! S0 6 ! r r +$ 6G '+\! .'+
5!,.! r )S! ' !  0 ' !/. ! 'r. A  0 'S". A 'S 
'S+ . ' a ! u '. g  r ! '+ . 'S. ' " ! r ! ! ' rwr
'". .! I  5 8#"%S0 ! u '. .'  ! '  5 %r# *83
!,.!S0 z ! ! r  !! . ! # r -'*)S!+ w-! ! '
r )! '+\! .'+ 5!,.! r )! ' y !  7 P !0 ' 6 !,. !
+\' ' ' .! "  ' F )S! -`
F N4 L7
1r L 4  *7 [ #
5 L  4  *7 [ #
y !  F 4 ( 7 ,/,/ F 4 ( 7 F 4 + 7 //,/ F 4 + 7 ' u ' .\' '. !
!,.' A ' ! !,3"! ! 4 !z+\' ' ' .! r  ' .! !/.)! !
.' !/. ' -! r '. ! 7 0-" !'  .! .. " F 4 7 5 -'*)S!
! '  \ .! .. " F 4 7 1r0 ' r P ! !,3"! ! r )S! ' -!/!
+\!/. ! 'S..! 
y  (  ! ( ' re 'S+ . ' } ! u 'S. '. ` '. !,.' A ' !
!3"! ! i ' !/)S!/.0 ! ' t . '+ r 0' B  \ ' u " '
u ' 'S. ! !/.' A ' ! !,3"! ! 0 S3 Er K H [ 4  6 . ! '.
[ @ ".!# X 5 1 ! ! 7 .'  !  ' 
!Ir. 6 4m[ [ # 7
!/!/+\! .! + !/. rB ! u 4m[[ # 7 y   6 ! '+ . '
! u '. ! !/!

 
 !#"%$'&(')"+*,(.- /1032)45*7698*,:,;<-==5>
?@$'*BA5=0C2)4*,6D8*7:; -==E>
F /G FIH KJCLM-5NPO A)QSR5GUT1V)WPXY.Z\'Z]\_^W`ba
\ V)cedWffKYEZhgDWViZ\ Zj^5\'fd,WVZ\<fk
l ceZ,WfKcm^jnYEV)W'ohWfpYdYPqsrKYPfp^Yt^5\'fudWVZB\<fk l ceZ,WfKcm^dYPqsrKYPfp^Yvxw@!U$!#$<ym;
z *C'&'|h:{2 ;|72*7~*,(~'8P&'}9$'|7"]2~E!{2"{:h6]&*258<!{"+"{22~'~|O
LP!{$'*,E&'$'&*,25~<!{|**"{<;" &<z :{2 *%( <$<|74*,*3!~b|726]~<&<|25:{:+:+!#*,25|~9"{y}_~'*7!{" 2z :{25"{*:{(
z2$ "+&'$ "O3'*7~M"+'*7:+*D:+**7~E"+:{*,!3Px2
"{'*B~'&'$'"!{*,E$'*7~|*D!{$<|h"{<"
&'&*,:+!U2~~j2$ "+&'$ " :+*C82)45*3E{O H 2~<!{( *7:U"{'*@625~'2"+2~'*C~<|7:{*!{~<D=)Qh/
$'~<|"{2~545*7~8P} z
Fe GU ='/ ..FF EEuu,,G{G{--
LP~<|*6]2~<2"{25~'*~<|7:{*!{~<B$'~<|"{2~<!C|7:+:+}~<|7:{*!{~']!{*,E$'*7~|*,!x"+2~<|7:{*!#Q
~<!#*E$'*7~<|7*,!@~<(( *|:+*,5!#~'t!{*,E$'*7~|*,!%"{2( *|:+*,5!#~'t!{*,E$'*7~|*,!,;'"+'*7}y!{2
|7:{:+}D8'"{25~'|3!#*E$'*7~<|7*,!
"+28'"{2~<|3!{*,E$'*,~<|*!7O FI ~<*C|7~t!#*,*"{'!8P}8':{*P~'
"{'*D8'"+2~'|B!{*,E$'*,~<|*~E"{2]" z 2j&'*|*!7;'25~'*2 z '|h!3~<|7:{*!{~<]~<(2~'*D2
z~<'&'$ |h"t"{!x'*( *,=|7Q+:{/*!#!{*5~<$<<*7;5~<|7~<*( "{:hF ~G !F "{25':{*6]!#~'*5$<"{*7<~<*7|76* ~'( 254P!{*t( $<I"{uyy}*7O~EGB"{:+S~}&<!:{ "{F | $' G#yG;
:;"{25'~ *
|256&:+!{2~~<*" z 2:+_&<:{2 ( $<|7*,!92$ "+&'$ " z "{z F Gj/2~~u25$ "{&'$'" z :+*
82)4*B F PIG=<O
S~<|( *,~5"hyy}5;'6j~P}t&*725&'y*B|7y6]*("+<)"C6]2~<2"{25~'*~<|:+*,5!#~']!#*5$<*7~<|7*
"{:h~<!#2:+6j!B~u~<|72:+:{*|"+y}_!#25:#"+*,(!#*E$'*7~<|7*t~5"+2~'2"+'*7:B~<|72:+:{*|"{y}!{2:{"{*(
!#*E$'*7~<|7*O'!D!~'2"]5$<"+*t"{:+$'*5O<2:9*'6]&'y*;|72~<!{('*7:B"+'*M|26]&<:{!{2~
~'*" z 2:+ z "+" z 2 z :{*!9~<(b~'2_|26]&<:+"{25:+!,O'!9!{2:{"+!D"{<*~'&'$ "/5{=E
~|2:+:+*,|"+y}5;8'$ ",;! "{'*6]2~'2"{2~<*U~<|:+*,5!#~'%$'~|"{2~ z '|hB!
=32:p*74*,:{}
~<&'$ ",;U"{'*,~u"+'*M|26]&<:{!{2~b~'*7" z 25:{b!{2:{"+!D"{'*~<&'$ ".m F /Gh F =EG#]e=<{=E
|25:{:+*,|"{y}O
F -G FIH KJCL-ENPO Qh/G1T1V)WPXYZ,[p\ Zb\^5W`ba
\ V)cedWffpYEZ+g9W<ViZ\'Z^5\'f`YEV)Y
\'fkZhgDWdW<VZYEcefcefp^V)YP\'d,cmfKW<V)pY5V_n5Y5V)W<o+WfKYd,YPqsrpYPfK^5YEducefZ,W\
d,cmfKeYd,WVZ,YPdYPqsrKYPfp^Y^\'f`YEV)Y\'fkZhgDWd,WVZ,YP#cefcefp^V)YP\'d,cmfK
W<V)pYEVdYEqsrpYPfK^5YPdcefZW\d,cmfKeYd,WVZ,YPd,YPqsrpYEfp^YvbwC!9~u:+28'y*76/;
*t:{5$'*]8P}|25~E"{:h&25!{"+25~OLP$'&<&2E!#*]"+<)"mh1!B~~'&'$ "|2~!#!"+~<2
"z z 2b!{2:{"{*( F ~~<|:+*,5!#~'2:h( *7:G9!#*5$<*7~<|7*,!ju~<(;~<("{<" z *M<45*
|256&:+!{2~~'*" z 2:+ z '|h( 2P*,!~'2"B!#25:#""{'!~'&'$ "B|72:+:{*|"{y}O'*7~"{<*7:+*
:+**7~E"{:+*!
+2"+'*,!{*" z 2!{*,E$'*7~|*,!!{$<|h9"{<"U+&'&*,:h!
2~]~2$'"{&'$ "
z82:+"{*9u|7822)6]45*]*D:+{2O 6F w3y;K"{'2525:B$'2~<_*j6~<E(."9h|726]|7*j~'~':+22"682"{_~<|(26]2*D~'*]:{25:+6 ;"{<*7}6]5E"
26OM32 z *745*7:;
"{'!%( 2P*,!{~ ":+*,yy}]6j)"#"+*7:O G H 2~!#( *7:"+'*@6]25~'2"+2~'*@~<|7:{*!{~<9=)Qh/3$<~<|"+25~
F GU ='/ .. F uh7G+-
F uh7G+-'
'*7~ F G~<(t F G F ( *7<~'*,(!~U:{258'y*,6/G:+*3!#"{yy6]2~'2"{2~<*3~|:+*,!{~'
!#*E$'*7~<|7*,! F mO *O;)!#25:#"+*,(!#*E$'*7~<|7*,!hG;8'$ ";25~1~'&<$ ""{<*U=)Qh/!#*5$<*7~<|7*3m F G+ F 7G#;
2$':|726]&<:{!#25~B~'*7" z 25:{12$'"{&'$ "h!U F Gx/2~]~92$ "+&'$ " z :{*82)4*% F GU
='O
F A5G FIH KJCL-5N O QAEGx [KWPgZ,[p\ Zj\'fkfpYEZhgDW<ViZ,[p\ Zt^\<f`YEV)YM\d,cmfKeYMYPf o
Z7VkgjcZ,[\dW<VZ,YPdYPqsrKYPfp^YWDmYEfpZ,[ F /GcefZW\d,cmfKeYbdW<VZYE


,d YPqsrpYPfK^5Y[K\'d]pYEaKZ[\'Z]mYP\'d7Z9y25 v"%!"+*76]& "+~'"+2:+*,5!#25~!x25yy2 z !7
# *.:+*"{:+}E~'"+2( *"+*7:+6~'*M"+'*&':+2&*7:t&25!{"+25~21"{'* *P"{:h'*,y*,6]*7~E",O
S~'"{yy}5;
"{'*,:{*:{* &25!+!{8'y"+*!2:D"{'!B&25!{"{2~Ox|hb|256]&<:h)"+2:B|7~
|$ ""+'*]~P$'6D8*7:12&2E!{!{8'y"{*,!)"6]25!#"1~_<y; !{2 z *~'*7*("y*!#"y2
|256&:h)"{25:+!,O '*7:+*:{*]" 2.&':+28'y*76j! "{"{'!7jp:+!#",;p"{)"D"|72~ $<!{*,!
"{'*j( *,& "{_2U"{'*~'*" z 2:+ z z "+"+'*~E$<6D8z *7:12x|726]&<:+"{2:h!,O'!&':+28'y*76
( 2P*,!{~ "!#*,*76!{2b!#*,:{2$<!,;x!{~<|*M"!#*,*76j!]~!{26]*M~ 25:{6jy3!#*,~<!#*"+<)";x8*Q
|7$<!#*9"{<*|726]&<:h)"+2:h! )"t4*,~( *,& "{:{* ~'25~ Q|726]&*"{~'E';2~'y}2~<*
2"+'*76|7~~P452y4*1"{<*t *P"{:h''*,y*,6]*7~E",;'*7~|*D&<:{2)4P( *$<!{*$'yp~'2:+6]"{2~O
LP*,|72~<(;"+<)" *3|7~]*"xy$<|hP} "+tB|256&:+!{2~OK'2:U*'6]&'y*;E~~'"{y
|256&:h)"{25:|7z2~'~<*,|"+~<9"+'*&*7~Pz $'y"{6]"{*B~<($<y"+6j)"+* z :+*,!!{'2 z !x"{<"%"{'*
~<&'$ "925~_"{'*j$'y"{6j)"+* z :+* F "+'* *P"{:h' *7y*76]*7~E"hG!8<5*7:1"+<~"+'*t~'&'$ "
2~M"+'*B&*7~P$'y"{6]"{* z :+* F "+'*By!#"C*7~E"{:+}2
"{'*D!{2:{"{*(M:+:+}'G;P"+'*7~ z *B<45*
6]*7:+*,("{'* *P"{:h'*7y*76]*7~E"~( *7&'"{u/5O <)" z *~'*,*,(M"+2!{'2 z !C"+<)" z *
( 2~ "3<45*"{'!P~<(2py$<|ht25~ ~'&<$ "+!,O
*9( 2]"{'!%$<!{~'t]8'~<:+}t"+:{*,* '|hM8*7<45*,!y5*Bj( *,|7!{2~"{:+*7*O H 2~ Q
!#( *,:%"{:h|7~'9"{<*62)45*76]*7~E"%2p"{<*]z *7E"+:+< *7y*76]*7~E"%"+':{25$'2$<:3|26]&<:{!{2~
~'*" 2:+OU|h"{6]*"t&!+!#*!D"+':+2$'5b|726]&<:h)"+2:;"t62)45*,!9"{2b*,"+'*7:
"{'*Dz "{25&2:%"+'*B82"#"+262
"{)"|726]&<:+"{2:OU'*D~'2~ Qy*,)~'2 ( *!32
25$':%"+:{*,*
z&<y!+y!,8Op*@y'*C8*,y*7yy*,"x(]|h'8P}9y(]"{'2*|2~<6]2P('&<*:+"{y25y:+|7!K2"{:+<:{*:{25!#&$'2~< (Dz "{'2B|h"{]'*"{< **CP*"+P:+<"+:+1*7y*,*7y6]*,6*7~E*,"~E"x6]6]2)4P5~<E "
"{2D"{'*82"#"+262s"+'*|726]&<:+z"{2:;~<(]"{<*@:+5E"x|h'y(]"+2B"+'*D *P"+:+<*7y*76]*,~5"
6]2)4E~'"{2"+'*"{2& O]<*jy*)x~<2P('*,!:+*y8*,yy*,(8P}"{'* z :+*25~ z <|h"{'*
*7P"{:h' *7y*76]*,~5"38*7y2~<5!,O
<2:%*7 6]&'y*5;P"{'*B|726]&<:{!#25~~'*7" z 25:{
a b c d

<!"+'*1"{:+*7*
b

c d

3 d 2 1

O
30 2"{|*B"+<)"@"{'*'*,552"2U:{*1|h<8'y*y*,!@~'2625:{*B"{<~"{'*]( *,& "{2
"{'*C~'*" z 2:+OpLP~<|*"+'*7:+*3:+*%)"y*,!#" :{*|h<8'y*y*,4*! F "{<* *7P"{:h')*7y*76]*,~5"
<!"{298*8'y*%"{298*@6]*7:+*,(~E"{29~P}D&25!{"+25~G;E"{<*C'*,55"x!)"Uy*,5!"xy25 O
P$<!"{<*B( *7& "+M!%y!{2j)"%y*!#"3y25 O

   !" #!$
%'&)(*%+(,-(/.102(4357698:8<;
=?>@BACD!E/FHGJI<KMLNJIPOJKQCR!SHI<TUCVWI<X)Y)SHZJY)L/F[D!\]Y^O_C2Sa`bD!CTcFHY)Sed=af2@gYhLiYjOkCFHDL
f7l<mon1NJI<KQIYhKQIpYBO_C2Sa`bD!CTcFHY)SJqM=af2@WY)DJGYBDrZJTjR_I<K1stE/Z!uvNcLNJYhLgd=af@kw
=afyxfl9@?qi=[f2@hzBs {
Y)DJGu:S[I YhKQS[`|d=aflv@_w}s mg~pF[XI DcYG!I \7KQI IR_C2ZJD!G||V CK
d1=[f2@Y)D!GLNJI|u:CIcuF[I DLX2I u9L/CKc[ r/4/-)v<l{tKQFaL/I|Y)DY)SH\CKQFaL/N!T
L/Cju:C2T]O!ZJL/IsMY)D!GcL/N!Ipu:CbI<cu:FHI DLgXI u9LC7KMC2Vqi=af@WF[DL/FHTcI=a@-mk+9 (
79 5
?7,4( d=af@y7 1h(43(/(-0 &)7 5!h<h)0 p2: < .t :fBxf l 9
h(43(/(-0 &)7 > ::(/ hr & : (4 ': h(43(/(-0 &)7 x>: & )2 ( 7Q' (
& 9 (/ qi=af@Ww lM f + (4P.& 7 )0 fx|f7lt , : (/, 7
:( (43.i::(/
b b
=afMx^f l @?qM=af2@kw l f z l =?x f l @f
hr

w r f z = r x f l @f z=x l f l @-

b ( & :2d=af@bxps 5h , 7 , (-M,4(/ :(, 3 H 44/4 l zPs9 5
(/ (, (4i,4(/ .1&7 02(( & : 5 hr w 5 r x f l w 7
x l f l w l x]s ' ( ! (4.0 ( ( & 9 (/ (&7& 9 :5 3 7
p (. )2, (/3. 7p 3<) 3) ( ( )2, 
oJJbr)r =H?f l @
> ,-3( 9 (o:(, 3
6 hr
VC7K!wx> B>
b z fl
; I DJG!VC7K
sy<lkz l4f7l
* KQI<L/ZJKvD ?s9
(g3( h(43 ) & B, (/, 79Ws 5 :( (/3 B ( 2: .t 9qi=[f2@ 7 (
, (-M,4(/ :(, 3+ 5b 9 (( & Q 7 0 (:5 (4,-( 3( , 33(,
& _ 7,4( ( VC7K1 : (-h(,-& (/ x>o .(45 7( , 7 3&, :(/
=>v@k .(57oJebr)b 7 3&))) .t( =a@-
= 6 @BbZJO!O_CEILNJY)L1IN!Y:X2I=[^z>@O_CFHDL/E[f ? {tw 8 44/-?{tiN!IKQI
f w fhiF[V wc m1bN!C LNJYhLiLNJIuCbI<cu:FHI<DLtX2I<u:L/CK[ /4/- l yC2V

d=af2@kw l l f fMx^xjf f)
vb
u:Y)DRkIu:C2T]O!ZJL/I GF[DL/FHTcIB=[b/@-m (y0 9 (4)(,M (, . & 9 9
( 3 )&7, vb =afyxf)@ 5<( , i: , P=HQ_ ( ,4, 3h) (W 9 &)3 9
9) 3 < , @9 3( ) (/ .t( =ab@_+9 ,4(:5 ) (4(435 79 5) k(, . & (
( & W 3 h&7, P= | .t ( (43.i @ ,-(:5 (/(, 3(/, :(43 (
3 )&7, j < 7( (/3. .t (/0 ?) (h ? 5 , (,
&), B0<_3 0 (/. >=H (13( h(43o 7 & :(/3 a 3o ?( 7Q (, ) :
, . & ( (gh(4 .t Q 3&7) 3, @
W: ( 7Q 5r k( 7 :(1 M[ 3o, . & (/ ( 3 )&7, yi=af2@'wh b f r z
4/zj fz^ l & &7 02( a 3( ( :j (43.B5 (/b5 y|e3 0 (4. > 5 (

3 )&7, 7, &7h) 7Q (43.
r
i=af@-=afxjf @ewc rf z = rx f @f z=?x7l/f @

&7e(+, M, . & ( (+07 3 h&7, k a: W ! ( 3:&).t(/ e (43(W (
33 t 8 /4 ) ?( (4 3M [f ?  >42w}f 7 H 6 2w
yabo2J = @
> ,-3( 9 (o:(, 3
6 >
VC7Kyw 8 ix>
)W) r
; VCK1!wx> B>
r x  : >-
*
I !
D J
G
V CK

'
l
x7l  : >-
Q
K <
I /
L J
Z Q
K D
> 8 I DJG!VC7K
(y3( h(/3 ) & , (/, 7Qi[ (, (-M,4(/ :(, 3 9 r l =[ftxf @?
 : < 3 a 3 ( & (43 VCK1<b_ L/I<KQTcF[D!YhL/FHCD 5 W h 7Q
(g, (4i,4(/ (/, 3 :J (0) 3 h&7, 79 k(y /e 7,-( ())(43
VC7K  (4h(/,-& (/' =a@ .t(/ a 3W( , (-h(/,4& :! ( & (43 V CK :h (
& (43 VC7K1 : (-h(/,4& (  .t(/ ) 7(4:(/3t7 3&7, :( .t( =>v@ 5h(
7 :( 7Q ya'J  7
3&)7)7 .(+ =[b@-= [ , 5:   e( )
79 + , & 9  3&)))) .t( =a @ 5)0)& (  )(/(/ (43( @
e(4 ) &) ( : 3 . 02(  ,h :9 :W &)7, 5   &7
, 33 ) & t ( 3 a 3 3^h( j9o) 0)&7 & d=af2@ =ab/@
)) 9 .t(
bJ J = @
>^B (/) 7x>
6  ya'J  = @
,-3( 9 (o:(, 3
VC7K!w>'t
;
 oJebr)b =  >-a@ >-
VCKow 8 ipx>
* >
FHV w
=af x^f @
>8 I D!GJFHV
>:> I D!GJVCK
> 6 VCKow 8 ipx>
> z  H 6 

> I D!GJVCK
> ; I DJG!VC7K
> KQI<L/ZJKvD
= y-7r^ ( 9 3 .h(,4302(/e3 0 (/. >'W: ( 79' )(
;^ &  )) 
(P, (-M,4(/ (/, 3 :' ( & 9 (/ i:' (0)
3 )&7, , . & (/ 0 :(y0 fx  >- 5h ( 5 fMxjf _ (g(4 3   >4 7 (
(47102(/, &7(( 3( 3 ) ( (/3. s , oJr)r

9  r3 h&7,4(/ @ (M 3( h(43g ) & |, (, Q (, (-M,4(/ :(/, 3
9 l b   p : 3 ya 3 ( & (43 VCKM<b
L/I<KQTcF[D!YhLF[C2D 5   h  7Qt7: ) (, (-M,-(4 (/, 3 9 (h(?3(
 .t :H 99 ())(/3 V CKW : !(-h(,-& (  .t(/ a 3!(/:(/3(4 (,-&
9 ( & (43 VCKk :b ( & (43 VCK_ : (-h(/,4& (  .t(/ 9 7r5(-),4( hra 3 (
?) (, 9J ya'J  = , 3&)7' .t(t =[b@@ 5r(4(437 3&7,
:(/ .t( =?>@e &7 ( 9 3 . 7 3&)))) .t( =ab@
Solution Manual for:
Introduction to ALGORITHMS (Second Edition)
by T. Cormen, C. Leiserson, and R. Rivest

John L. Weatherwax

December 17, 2013

Acknowledgments

Special thanks to Avi Cohenal for finding typos in these notes. All comments were (and are)
much appreciated.


wax@alum.mit.edu

1
Chapter 1 (The Role of Algorithms in Computing)

1.1 (Algorithms)

Exercise 1.1-1 (sorting, optimally multiply matrices, and convex hulls)

Sorting is done in all sorts of computational problems. It is especially helpful with regard
to keeping data in a understood ordering so that other algorithms can then work easily
and efficiently on the underlying sorted items. One such example of such an algorithm is
searching for a specific key in a sequence of elements. When the elements are sorted searching
can be done more efficiently.

Selecting the optimal order to multiply matrices can occur in programs/algorithms that
update their state through linear transformations. When this is the case, and the trans-
formations can be cashed, in other words they dont need to be performed immediately, then
computing an optimal ordering in which to calculate the individual matrix products could
radically reduce the total computational time.

Finding the convex hull occurs in many graphics programs where the convex hull finding
algorithm needs to determine the largest box required to contain all the given data points.

Exercise 1.1-2 (measures of efficiency)

Other common measures of efficiency used to compare algorithms could be anything that
might be constrained in a real world setting. Examples of this are memory constraints
both disk and random access memory (RAM), the number of memory accesses, determinism
as opposed to a randomize algorithm, number of files created, number of sockets opened,
number of Internet connections established etc.

Exercise 1.1-3 (an example data structure)

A common data structure often used is a linked list. Such a data structure can easily insert
items into any location within the data structure once the desire insertion point is known. A
linked list structure cannot locate new elements or locations quickly since it must effectively
look at each element one at a time until the desired one is found.
Exercise 1.1-4 (shortest-path v.s. traveling-salesman problems)

In the shortest-path problem the path through the network is often only one way. It is not
required to end up at the starting location, but just to end at the last destination desired.
In the traveling-salesman problem the algorithm must start and end at the same location
while visiting all other destinations en-route. This requirement that we start and end at the
same location while visiting all intermediate locations makes the problem more difficult.

Exercise 1.1-5 (when only the optimal will do)

There are relatively few situations in real life where only the optimal will do. This is because
normally in formulating a physical problem into a framework that an algorithm can solve
involves approximations and simplifications and using an approximate algorithm (assuming
that it is not way off of optimal) does not introduce errors greater than have already been
introduced in the approximations up to that point.
Chapter 28 (Matrix Operations)

28.1 (Properties of Matrices)

Exercise 28.1-1 (elementary properties of transposes)

These two facts are a simple consequences of the definition of a transpose: the (i, j)th
element in M T is the (j, i)th element in M. For A + B we have that the (i, j)th element in
(A + B)T is the (j, i)th element in A + B, which is the sum of the (j, i)th elements in A and
B individually, which is also the sum of the (i, j)th elements in AT and B T individually. So
we have that the (i, j)th element in (A + B)T is the same as the sum of the (i, j)th element
from AT and B T . Since A and B are symmetric we have that
(A + B)T = AT + B T = A + B
and the matrix A + B is symmetric. The proof for the difference of A and B is done in the
same way.

Exercise 28.1-2 (transpose of a product)

To prove that (AB)T = B T AT we begin by looking at the components of the product AB.
For simplicity assume A and B are n by n. Then the (i, j)th entry of AB is given by
n
X
(AB)i,j = Ai,k Bk,j .
k=1

Then the transpose of AB has components given by


n
X
T
((AB) )i,j = (AB)j,i = Aj,k Bk,i .
k=1

Note that the components of A in the above can be expressed in term of As transpose since
Aj,k = (AT )k,j . The same can be said for B and when this substitution is done we have
n
X n
X
((AB)T )i,j = (AB)j,i = (AT )j,k (B T )i,k = (B T )i,k (AT )j,k .
k=1 k=1

Where in the first summation we have replace Aj,k with (AT )k,j (similarly for B) and in the
second summation we just placed the term B T before the term involving AT . The above can
be recognized as the (i, j)th element of the product B T AT as expected.

Using the fact that (AB)T = B T AT (proven above), and that (AT )T = A, for the product
AT A we have that
(AT A)T = (A)T (AT )T = AT A .
thus since AT A when transposed equals itself we have that it is a symmetric matrix as
requested.
Exercise 28.1-3 (uniqueness of a matrix inverse)

If we assume (to reach a contradiction) that both B and C are inverses of A then we must
have that
AB = I and BA = I
AC = I and CA = I ,
Multiplying the equation AB = I on the left by C gives CAB = C. Using the fact that
CA = I, the above simplifies to B = C, showing that the inverse of a matrix must be unique.

Exercise 28.1-4 (triangular matrices)

We will prove that the product of two lower triangular matrices is lower triangular by in-
duction. We begin with n = 2 for which we have
    
l11 0 m11 0 l11 m11 0
=
l21 l22 m21 m22 l21 m11 + l22 m21 l22 m22
which is lower triangular. Assume the product of two lower triangular matrices of size nn
is also lower triangular and consider two lower triangular matrices of size n + 1. Performing
a bordered block partitioning of the two lower triangular matrices we have that
   
Ln 0 Mn 0
Ln+1 = and Mn+1 =
lT ln+1,n+1 mT mn+1,n+1
where the single subscripts denote the order of the matrices. With bordered block decom-
position of our two individual matrices we have a product given by
 
Ln Mn 0
Ln+1 Mn+1 = .
lT Mn + ln+1,n+1mT ln+1,n+1 mn1 ,n+1
Since by the induction hypotheses the product Ln Mn is lower triangular we see that our
product Ln+1 Mn+1 is lower triangular.

The fact that the determinant of a triangular matrix is equal to the product of the diagonal
elements, can easily be proved by induction. Lets assume without loss of generality that
our system is lower triangular (upper triangular systems are transposes of lower triangular
systems) and let n = 1 then |G| = g11 trivially. Now assume that for a triangular system
of size n n that the determinant is given by the product of its n diagonal elements and
consider a matrix G of size (n + 1) (n + 1) partitioned into a leading matrix G11 of size
n n.  
G11 0
G= .
hT gn+1,n+1
Now by expanding the determinant of G along its last column we see that
n
Y n+1
Y
|G| = gn+1,n+1|G11 | = gn+1,n+1 gii = gii ,
i=1 i=1
proving by induction that the determinant of a triangular matrix is equal to the product of
its diagonal elements.

We will prove that the inverse of a lower triangular matrix L (if it exists) is lower triangular
by induction. We assume that we are given an L that is non-singular and lower triangular.
We want to prove that L1 is lower triangular. We will do this by using induction on n the
dimension of L. For n = 1 L is a scalar and L1 is also a scalar. Trivially both are lower
triangular. Now assume that if L is non-singular and lower triangular of size n n, then
L1 has the same property. Let L be a matrix of size (n + 1) (n + 1) and partition L as
follows  
L11 0
L= .
L21 L22
Where L11 and L22 are both lower triangular matrices of sizes less than n n, so that we
can apply the induction hypothesis. Let M = L1 and partition M con formally i.e.
 
M11 M12
M= .
M21 M22
We want to show that M12 must be zero. Now since ML = I by multiplying the matrices
above out we obtain
  
L11 0 M11 M12
LM =
L21 L22 M21 M22
   
L11 M11 L11 M12 I 0
= =
L21 M11 + L22 M21 L21 M12 + L22 M22 0 I
Equating block components gives
L11 M11 = I
L11 M12 = 0
L21 M11 + L22 M21 = 0
L21 M12 + L22 M22 = I.
By the induction hypothesis both L11 and L22 are invertible. Thus the equation L11 M11 = I
gives M11 = L1 11 , and the equation L11 M12 = 0 gives M12 = 0. With these two conditions
the equation L21 M12 + L22 M22 = I becomes L22 M22 = I. Since L22 is invertible we compute
that M22 = L1 22 . As both L11 and L22 are lower triangular of size less than n n by the
induction hypothesis their inverse are lower triangular and we see that M itself is then lower
triangular since  1 
L11 0
M= .
M21 L1 22
Thus by the principle of induction we have shown that the inverse of a lower triangular
matrix is lower triangular.

Exercise 28.1-5 (permutation matrices)

From the definition of a permutation matrix (a matrix with only a single one in each
row/column and all other elements zero) the product P A can be computed by recognizing
that each row of P when multiplied into A will select a single row of A and thus produces a
permutation of the rows of A. In the same way the product AP will produce a permutation
of the columns of A. If we have two permutation matrices P1 and P2 , then P1 acting on P2
will result in a permutation of the rows of P2 . This result is a further permutation matrix,
since it is the combined result of two permutations, that from P2 and then that from P1 . If
P is a permutation, then it represents a permutation of the rows of the identity matrix. The
matrix P representing the permutation which reorders the rows of P back into the identity
matrix would be the inverse of P and from this argument we see that P is invertible and has
an inverse that is another permutation matrix. The fact that P 1 = P T can be recognized
by considering the product of P with P T . When row i of P is multiplied by any column of
P T not equal to i the result will be zero since the location of the one in each vector wont
agree in the location of their index. However, when row i of P is multiplied by column i the
result will be one. Thus we see by looking at the components of P P T that P P T = I and
P T is the inverse of P .

Exercise 28.1-6 (Gauss transformations)

Lets assume (without loss of generality) that j > i, then we will let M be the elementary
matrix (of type 1) that produces A from A i.e. it adds row i to j and the sum replaces row
j. Then since AB = I multiplying this system by M on the left we obtain (since MA = A )
that A B = M. From this we see that by multiplying this expression above by M 1 on
the left we obtain A BM 1 = I, showing that the inverse of A is BM 1 . Now the matrix
M is like the identity by with an additional one at position (j, i) rather than a zero there.
Specifically we have
1

1
..


.

M = 1 .

1


..
1 .
1
Where the one in the above matrix is at location (j, i). In this case the inverse of M is then
easy to compute; it is the identity matrix with a minus one at position (j, i), specifically we
have
1

1
..


.

M 1 = 1 .

1


. ..

1
1
Now multiplying B by this matrix on the left will operate on the columns of B, thus B =
BM 1 is the same matrix as B but with the jth and the negative of the ith column added
together and placed in column j. That is we are subtracting the ith column from the jth
column and placing it in column j.

Exercise 28.1-7 (the realness of A1 )

Lets begin by assuming that every entry of A is real and then show that every entry of A1
is real. The easiest way to see that all entries of A1 must be real is to recall the adjoint
theorem from linear algebra. The adjoint theorem gives the inverse of a matrix in terms of
the adjoint of that matrix. Specifically, the adjoint theorem states that
1
A1 = CT ,
det(A)

where C is the matrix of cofactors of A. This cofactor matrix C is the matrix such that its
(i, j) element is given by the cofactor of the element aij or

Ci,j = (1)i+j det(A[ij] ) .

Where A[ij] is the ijth minor of the matrix A, i.e. the submatrix that is produced from
A by deleting its ith row and its jth column. Because the determinants of the minors of
A only involve additions and multiplications, if A has only real elements then all cofactors
and determinants of A must be real. By the adjoint theorem above, A1 can have only real
elements. The other direction, where we argue that if A1 has only real elements then A
must have only real elements can be seen by applying the above arguments to the matrix
A1 .

Exercise 28.1-8 (symmetry of the inverse)

Let A be symmetric and invertible. Then by the definition of the inverse, A1 satisfies
AA1 = I. Now taking the transpose of both sides and remembering that the transpose of a
product is the product of the transposes but in the opposite order we have (A1 )T AT = I T
which simplifies to (A1 )T A = I, since both A and I are symmetric. By multiplying both
sides on the left by A1 we have that

(A1 )T = A1

showing that A1 is symmetric.

That the product BAB T is symmetric is just an exercise in taking transposes. We have

(BAB T )T = (B T )T AT B T = BAB T ,

and this product of matrices is symmetric.


Exercise 28.1-9 (full column rank)

Lets assume that A has full column rank and that Ax = 0. Note that Ax = 0 is equivalent
to the statement that a linear combination of the columns of A sums to zero. Specifically if
vi represents the ith column of A then Ax = 0 is equivalent to
n
X
xi vi = 0 .
i=1

Since A is full column rank its columns are linearly independent (this is the definition of full
column rank). Because of this fact, the only way these columns can sum to zero is if x = 0
and we have proven one direction. Now lets assume that Ax = 0 implies that x = 0. This
statement is equivalent to the fact that the columns of A are linearly independent which
again implies that A is of full column rank.

Exercise 28.1-10 (rank inequalities)

To show this we will first show that

rank(AB) rank(A) .

and then use this result to show that

rank(AB) rank(B) .

When these two results are combined the rank of the product AB must be less than the
smaller of the two rank(A) and rank(B) giving the requested inequality of

rank(AB) min(rank(A), rank(B)) .

To show that rank(AB) rank(A), we first note that every vector in the column space of
AB is in the column space of A. This is true since AB is the action of the matrix A on every
column of the matrix B, and the action of a matrix (A) on a vector is a linear superposition
of the columns of that matrix (A). Thus the number of linearly independent columns of the
product matrix AB cannot be greater than that of the number of linear independent columns
in the multiplying matrix (A) and we recognize the desired result of

rank(AB) rank(A) .

To show the second inequality rank(AB) rank(B), we apply the expression proved above
on the matrix (AB)T . Since this matrix equals B T AT we have that

rank((AB)T ) = rank(B T AT ) rank(B T ) = rank(B) .

But since rank((AB)T ) = rank(AB) replacing the first term in the above gives

rank(AB) rank(B) ,
showing the second of the desired inequalities. If A or B is invertible, it must be square
and its rank is equal to its number of columns (equivalently the number of rows). With out
loss of generality assume that A is invertible. By the arguments above when we multiply B,
the dimension of the column space of AB cannot change from the dimension of the column
space of B. Thus we have that

rank(AB) = rank(B) .

The same argument applied to (AB)T (as outlined in the inequality proof above) can be
used to show that if B is invertible that

rank(AB) = rank(A) .

Exercise 28.1-11 (the determinant of the Vandermonde matrix)

Following the hint given, we will multiply column i by x0 and add it to column i + 1 for
i = n 1, n 2, , 1. This action will not change the value of the determinant but will
make it simpler to evaluate as we will soon see. We begin by first multiplying column n 1
by x0 and adding to column n. We find that

1 x0 2 n2 n1
x 0 x0 x0
1 x1 2 n2 n1
x 1 x1 x1
det(V (x0 , x1 , x2 , , xn3 , xn2 , xn1 )) = 1 x2
x22 x2n2 x2n1
.. .. .. .. ..
. . . . .
n2
1 xn1 x2n1 xn1 n1

xn1

1 x0 2 n2
x 0 x0 0

1 x1 2 n2 n2
x1 x1 (x1 x0 )x1

1 x2 2 n2 n2
= x 2 x2 (x 2 x )x
0 2 .
.. .. .. .. ..
. . . . .
n2
1 xn1 x2n1 xn1 n2

(xn1 x0 )xn1

Where we see that this action has introduced a zero in the (1, n) position. Continuing, we
now multiply column n 2 by x0 and add it to column n 1. We find that the above
determinant now becomes

1 x0
x20 0 0

1 x1 2 n3 n2
x 1 (x1 x )x
0 1 (x1 x )x
0 1
1 x2 2 n3 n2
x 2 (x2 x 0 )x2 (x2 x 0 )x2 .
.. .. .. .. ..


. . . . .
2 n3 n2

1 xn1 xn1 (xn1 x0 )xn1 (xn1 x0 )xn1

Where we see that this action has introduced another zero this time at the (1, n1) position.
Continuing in this manner we will obtain the following determinant where the first row has
only one non-zero element

1 0 0 0 0 0

1 x1 x0
(x1 x0 )x1 (x1 x0 )x21 (x1 x0 )x1n3 (x1 x0 )x1n2

1 x2 x0 (x2 x0 )x2 (x2 x0 )x22 (x2 x0 )x2n3 (x2 x0 )x2n2 .

.. .. .. .. .. ..


. . . . . .
1 xn1 x0 (xn1 x0 )xn1 (xn1 x0 )x2n1 n3 n2

(xn1 x0 )xn1 (xn1 x0 )xn1
We can expand this determinant about the first row easily since there is only a single nonzero
element in this row. After this reduction we see that we can factor x1 x0 from the first
row of our reduced matrix, factor x2 x0 from the second row, x3 x0 from the third row,
and so on til we get to the n 1th row of our reduced matrix where we will factor xn1 x0 .
This gives us

1 x1 2 n3 n2
x 1 x1 x1
n1 1 x2 2 n3 n2
Y x 2 x2 x2
det(V (x0 , x1 , x2 , , xn2 , xn1 )) = (xi x0 ) .. .. .. .. .. .

. . . . .
i=1
2 n3 n2

1 xn1 xn1 xn1 xn1

Note that the remaining determinant is of size (n 1) (n 1) and is of exactly the same
form as the previous determinant. Thus using the same manipulations performed earlier we
see that
n1
Y
det(V ) = (xi x0 ) det(V (x1 , x2 , , xn1 ))
i=1
n1
Y n1
Y
= (xi x0 ) (xj x1 ) det(V (x2 , x3 , , xn1 ))
i=1 j=2
n1
Y n1
Y n1
Y
= (xi x0 ) (xj x1 ) (xk x2 )det(V (x3 , , xn1 ))
i=1 j=2 k=3
n1
Y n1
Y n1
Y n1
Y
= (xi x0 ) (xj x1 ) (xk x2 ) (xl xn3 ) (xn1 xn2 ) .
i=1 j=2 k=3 l=n2

As a bit of shorthand notation the above can be written as


Y
det(V (x0 , x1 , , xn2 , xn1 )) = (xk xj ) ,
0j<kn1

as claimed in the book.

28.2 (Strassens algorithm for matrix multiplication)

Exercise 28.2-6 (multiplying complex numbers)

We are given a, b, c, and d and we desire to compute the complex product


(a + ib)(c + id) = (ac bd) + i(ad + bc) ,
using only three real multiplications. To perform this computation define the some interme-
diate variables t1 , t2 , and t3 in terms of our inputs as

t1 = ad
t2 = bc
t3 = (a + b)(c d) ,

which involve only three real multiplications. Note that the product obtained by computing
t3 is algebraically equivalent to

t3 = (a + b)(c d) = ac ad + bc bd = (ac bd) + (ad + bc) ,

where we have grouped specific terms to help direct the manipulations we will perform below.
Note also that the sums t1 + t2 and t3 + t1 t2 are given by

t1 + t2 = ad + bc
t3 + t1 t2 = ac bd .

so that our full complex product can be written in terms of these sums as

(a + ib)(c + id) = (t3 + t1 t2 ) + i(t1 + t2 ) .

28.3 (Solving systems of linear equations)

Exercise 28.3-1 (an example of forward substitution)

Our problem is to solve


1 0 0 x1 3
4 1 0 x2 = 14 ,
6 5 1 x3 7
which upon performing forward substitution gives

x1 = 3
x2 = 14 4x1 = 14 12 = 2
x3 = 7 + 6x1 5x2 = 7 + 18 10 = 1 .

28.5 (Symmetric PD matrices and LS approximations)

Exercise 28.5-1 (diagonal elements of positive-definite matrices)

Since A is positive definite we must have for all non-zero xs the condition xT Ax > 0. Let
x = ei , a vector of all zeros but with a one in the i-th spot. Then xT Ax = eTi Aei = aii > 0,
proving that the diagonal elements of a positive definite matrix must be positive.
Chapter 31 (Number-Theoretic Algorithms)

31.1 (Elementary number-theoretic notations)

Exercise 31.1-1

Following the hint, given a sequence of increasing primes p1 , p2 , , pk we can form another
prime p by computing the product plus one or p = p1 p2 pk + 1. Note that this new
number p is prime since none of p1 , p2 , , pk divide it. If one did then it would also have to
divide the number p p1 p2 pk = 1 which is impossible. Thus the newly formed number
is prime and as we can repeat this procedure an infinite number of times there must be an
infinite number of primes.

Exercise 31.1-2

If a|b then we have that there exists an integer k1 such that b = k1 a. Since b|c we have that
there exists an integer k2 such that c = k2 b. Using the first of these two relationships into
the second we have
c = k2 b = k2 (k1 a) = k1 k2 a ,
showing that a|c.

Exercise 31.1-3

Assume that gcd(k, p) = d 6= 1. Then d|k and d|p. Since p is prime if d|p then d = 1 or
d = p. As we assumed that d 6= 1 we must have d = p. The fact that d|k means that |d| |k|
or |p| |k|. This last fact is a contraction to the problem assumption that k < p. Thus the
assumption that d 6= 1 must be false.

Exercise 31.1-4

Since gcd(a, n) = 1 then by Theorem 31.2 there must exist integers x and y such that
1 = ax + ny. If we multiply this equation by b we get

b = abx + nbx .

Note that the right-hand-side of the above is divisible by n since it is a linear combination
of two things (the terms abx and nbx) both of which are divisible by n. We know that abx is
divisible by n since ab is and nbx is divisible by n since n is a factor. Since the right-hand-side
equals b this shows that b is divisible by n.
Exercise 31.1-5

Using Equation 4 we can write    


p p p1
= ,
k k k1
p p
 
which since the right-hand-side is a multiple of p shows that p divides k
or p| k
. Next
note that using the binomial theorem we can write (a + b)p as
p1  
p p p
X p
(a + b) = a + b + ak bpk .
k=1
k
p

Since p divides k it divides the summation on the right-hand-side of the above equation.
Thus the remainder of (a + b)p and ap + bp when dividing by p is the same or

(a + b)p = ap + bp (mod p) .

Exercise 31.1-6

Now the definition of the mod operators is that


jxk
x mod b = x b (1)
j xb k
x mod a = x a.
a
Since a|b there exists an integer k such that b = ka. Thus Equation 1 becomes
jxk
x mod b = x ka . (2)
b
Thus taking the mod a operator to both sides of Equation 2 we get

(x mod b) mod a = x mod a ,

as we were to show. Next if we assume that x y (mod b) then taking the mod a operator
to both sides of this expression and using the just derived result we get

(x mod b) mod a = (y mod b) mod a or x mod a = y mod a ,

as we were to show.

Exercise 31.1-8

Recall that Theorem 31.2 states that that gcd(a, b) is the smallest positive element of the set
{ax + by : x, y Z}. Since this set definition of the greatest common divisor is symmetric
in a and b we see that
gcd(a, b) = gcd(b, a) .
and because x and y are arbitrary integers that

gcd(a, b) = gcd(a, b) = gcd(|a|, |b|) .

We also have that gcd(a, 0) is the smallest element in the set {ax : x Z} which would be
when x = 1 such that the product of ax is positive or |a|. Next we have that gcd(a, ka) is
the smallest element of the set {ax + kay : x, y Z} = {a(x + ky) : x, y Z}. This smallest
element would be when x + ky = 1 in order that a(x + ky) = |a|.

Exercise 31.1-9

Let d = gcd(a, gcd(b, c)) i.e. the left-hand-side of the equation we wish to show. Then d|a
and d| gcd(b, c). This second statement d| gcd(b, c) means that d|b and d|c. Since d divides
a and b by the above this means that d| gcd(a, b). Thus d is a number that gcd(a, b) and c.
Lets show that d is the largest number that divides both gcd(a, b) and c. Then if so we have
that d = gcd(gcd(a, b), c) and we have shown the desired equivalence. To show this assume
that there is another integer d such that d > d that divides gcd(a, b) and c. This means
that d |a and d |b, and d |c so that d | gcd(b, c). Thus since d divides a and gcd(b, c) it must
be smaller than or equal to the greatest common divisor of a and gcd(b, c) or

d d = gcd(a, gcd(b, c)) ,

giving a contradiction to the initial assumption that d > d. Thus means d must be the
largest integer already and so d = gcd(gcd(a, b), c).

31.2 (Greatest common divisor)

Notes on Euclids algorithm

Recall that a mod b = a ab b i.e. a mod b is the remainder when a is divided by b. This
 

is the common understanding


 a  when a > b. We nowa ask what does this mean if a < b? In
that case we would have b = 0 since the fraction b < 1 and the above formula would give

a mod b = a when a < b . (3)

To numerical examples of this are

5 mod 10 = 5
2 mod 5 = 2 .

The point of these comments is to give some understanding to Euclids algorithm for finding
the greatest common divisor when the inputs are EUCLID(a, b) where a < b then in this
case the first recursive call performed is

EUCLID(a, b) = EUCLID(b, a mod b) = EUCLID(b, a) .


From the above we see that now all recursive calls to EUCLID will have the first argument
larger than the second argument. In python, the greatest common divisor is available in the
fractions module i.e.

import fractions
print fractions.gcd(30,21) # the example from the book gives 3

At the time of writing the source code of this function shows that its in fact using Euclids
algorithm for its implementation.

Exercise 31.2-1

Let d = gcd(a, b) then d must have a prime factorization in terms of the same primes as a
and b namely
d = pg11 pg22 pgrr .
Since d is a divisor of a and b we must have d|a and d|b which means that

pgi i |a and pgi i |b ,

for i = 1, 2, , r. This in tern means that

pgi i |pei i and pgi i |pfi i .

Thus we have that


gi ei and gi fi .
For d to be as large as possible (since it is the greatest common divisor the powers gi must
be as large as possible such that the above two relations hold or

gi = min(ei , fi ) ,

as we were to show.

Exercise 31.2-2

See the output in Table 1 where we follow the output format given in this section of the
notes where as we move down the table we are moving in increasing stack depth. From that
output we see that gcd(899, 493) = 29 and that 29 = 899(6) + 493(11).

Exercise 31.2-3

One way to see that these two expressions are equal is to use one step of EUCLIDs algorithm
to evaluate both of them and see that after the first step both of these algorithms are
stack level a b a/b d x y
0 899 493 1 29 -6 11
1 493 406 1 29 5 -6
2 406 87 4 29 -1 5
3 87 58 1 29 1 -1
4 58 29 2 29 0 1
5 29 0 - 29 1 0

Table 1: The recursive calls resulting from executing EXTENDED-EUCLID(899,493)

computing the same thing. For example, EUCLID to compute gcd(a, n) would first call
(assuming n 6= 0)
EUCLID(n, a mod n) .
The first step of EUCLIDs algorithm on the second expression gcd(a + kn, n) would call

EUCLID(n, (a + kn) mod n) .

Since (a + kn) mod n = a mod n we have that the two expressions will evaluate to the same
number and are therefore the same. If n = 0 the we can see that both sides are equal.

Exercise 31.2-4

One way to do this would be the following in python

def iterative_euclid(a,b):
while b != 0 :
a, b = b, a % b # swap in place
return a

Here we have assigned b to a and a mod b to b in one step using pythons tuple assignment.

Exercise 31.2-5

For the Fibonacci sequence defined as F0 = 0, F1 = 1, and

Fk = Fk1 + Fk2 for k 2 ,


k+1

Then it can be shown that Fk+1 5
for large k where is the golden ratio defined as

1+ 5
= = 1.61803 .
2
From Lames theorem in the book we have less than k recursive calls in EUCLID(a, b) when
Fk+1 > b or using the approximation above for Fk+1 when
k+1
> b.
5
Solving the above for k gives

k > log (b) + log ( 5) 1 .
Note that we can evaluate the constants in the above using

ln( 5)
log ( 5) = = 1.67 ,
ln()
Thus we conclude that k > log (b) + 0.67. Thus we have shown that the invocation
EUCLID(a, b) makes at most 1 + log (b) recursive calls.

Exercise 31.2-7

One can show that the function returns the same answer independent of the order of the
arguments by induction. It is easiest to see how to write
gcd(a0 , a1 , a2 , , an ) = a0 x0 + a1 x1 + a2 x2 + + an xn ,
by looking at an example. Consider
gcd(a0 , a1 , a2 , a3 ) = gcd(a0 , gcd(a1 , a2 , a3 )) = gcd(a0 , gcd(a1 , gcd(a2 , a3 ))) .
We can now use Theorem 31.2 to write gcd(a2 , a3 ) as a2 x2 + a3 x3 for two integers x2 and x3 .
This would give
gcd(a0 , a1 , a2 , a3 ) = gcd(a0 , gcd(a1 , a2 x2 + a3 x3 )) .
We can again use use Theorem 31.2 to write gcd(a1 , a2 x2 + a3 x3 ) as
x1 a1 + y1 (a2 x2 + a3 x3 ) = x1 a1 + y1 x2 a2 + y1 x3 a3 .
for two integers x1 and y1 . Thus we have shown that
gcd(a0 , a1 , a2 , a3 ) = gcd(a0 , x1 a1 + y1 x2 a2 + y1 x3 a3 ) .
One more application of Theorem 31.2 gives
gcd(a0 , a1 , a2 , a3 ) = x0 a0 + y2 (x1 a1 + y1 x2 a2 + y1 x3 a3 )
= x0 a0 + y2 x1 a1 + y1 y2 x2 a2 + y1 y2 x3 a3 .
As each coefficient in front of ai is the product of integers it itself is an integer. This gives the
desired representation when n = 3. In general, we use the definition of the greatest common
divisor for n > 1 to nest gcd function calls until we get a function call with only two
arguments gcd(an1 , an ). We can then use Theorem 31.2 to write this as an1 xn1 + an xn
for two integers xn1 and xn . We can then unnest the gcd function calls each time using
Theorem 31.2 to get the desired result.
Exercise 31.2-8 (the least common multiple)

We can first compute the greatest common divisor of the given n integers

d = gcd(a1 , a2 , . . . , an ) .

This can be done using the recursive definition of the gcd for more than two arguments given
in a previous problem. Then since d is a divisor of each of ai it is a factor of each of them
(by definition). Once we have this number then the least common multiple is given by
a  a  a 
1 2 n
lcm(a1 , a2 , . . . , an ) = d .
d d d
In the right-hand-side
 of the above expression by grouping d with a given term in parenthesis
we have that d adi = ai and thus the above number is a multiple of ai for each i.
Appendix C (Counting and Probability)

Appendix C.1 (Counting)

a lower bound on the binomial coefficients (book notes page 1097)

The proof of the lower bound on the binomial coefficients given in the book, requires that
n1 n
,
k1 k
for 1 k n. We can show this expression is true, by starting with it and seeing if we can
convert it using reversible transformations to another expression known to be true. If this
can be done, since each transformation is reversible, the original expression must also be
true. For this expression we can demonstrate it is true by using some simple manipulations.
We have
n1 n

k1 k
k(n 1) n(k 1)
kn k nk n
k n
n k

Which is known to be true. Using the same manipulations we can show show that
n2 n
.
k2 k
This inductive process can continue, subtracting one each time from the numerator and
denominator. As a check we can verify the correctness of the final inequality which is given
by
nk+1 n
.
1 k
Using the same approach as above
nk+1 n

1 k
kn k 2 + k n
n(k 1) k(k 1) 0
(k 1)(n k) 0
and the last equation is true. Given this sequence of results we can derive the lower bounds
on the binomial coefficients as
 
n n(n 1) . . . (n k + 1)
=
k k(k 1) . . . 1
n n 1 
nk+1

=
k k1 1
n n n

k k k
 n k
=
k

a upper bound on the binomial coefficients (book notes page 1097)

We have from the definition of the binomial coefficients that


 
n n(n 1) (n k + 1)
=
k k(k 1) 2 1
k
n

k!
ek nk

kk
 en k
.
k
k
Where in the above we have used the k! ke (obtained from Stirlings approximation),
in the form
1  e k

k! k
nk
to simplify the expression k!
in the above.
the binomial coefficients and the entropy function (book notes page 1097)

If we assign k = n, then we have the following


nn
 
n

n (n)n (n n)nn
nn
=
(n)n ((1 )n)(1)n
 n
n
=
(n) ((1 )n)1
 n
1
=
(1 )1
   1 !n
1 1
=
1
2nH() ,
where the introduction of the expression H() above requires that
   1
1 1
nH() = n lg( )
1
or
H() = lg() (1 ) lg(1 ) .
This is the (binary) entropy function. We note before continuing that since = n/k the
above bound can also be written as
 
n n
2nH( k ) .
k

Exercise C.1-1 (counting substrings)

Assuming k < n, then the first substring occupies the locations 1, 2, . . . , k, the second sub-
string occupies the locations 2, 3, . . . , k + 1, and so on. The last possible substring would
occupy the locations n k + 1, n k, . . . , n. Thus we have in total
nk+1
substrings of size k in a string of size n.

To calculate how many substrings of size k a string of size n has, we from the above formula
that we have n size one substrings (k = 1), n 1 size two substrings (k = 2), n 2 size
three substrings, etc. Continuing this pattern the total number of substrings is the sum of
all these numbers given by
n n
X X n(n + 1)
(n k + 1) = l= .
k=1 l=1
2
Exercise C.1-2 (counting Boolean functions)

Each Boolean function is defined by how it maps its inputs to outputs. For an n-input,
1-output Boolean function we have a total of 2n possible inputs, to which we can assign
a TRUE or a FALSE output. Thus for each possible unique input specification we have 2
possible output specifications. So we have for the number of possible inputs (counting the
number of possible outputs for each input)

2 22 2.

With one factor of 2 for each of the possible input specification. Since there are 2n possible
input specifications, this gives a total of
n
22 ,

possible Boolean functions with n-input variables and 1-output variable.

For a n-input m-output we have 2m possible choices for each possible output, so using the
same logic as before we have
n n
(2m )2 = 2m2 ,
possible n-input m-output Boolean functions.

Exercise C.1-3 (counting professors)

Let the number of such ways our professors can sit be denoted by Nt , with t for table. Then
for each one of these seatings we can generate all permutations of n objects in the following
way. First consider a specific table ordering of professors say abcd. Then all the other
equivalent table orderings are given by circularly shifting the given ordering i.e. producing
bcda, cdab, dabc. This circular shifts produce n different. Since by performing this operation
on each of the Nt table orderings we get all possible permutations of which there are n!, so
in equation form we have that nNt must equal n!, which when we solve for Nt gives
n!
Nt = = (n 1)! .
n

Exercise C.1-4 (an even sum from distinct subsets of size three)

Our set is given by S = 1, 2, . . . , 100 and we want three distinct numbers that sum to an
even number. The total number of distinct size  3 subsets
 (independent of the order of the
100
elements in the subset) drawn from S is given by . Half of these will sum to an even
3
number and the other half will sum to an odd number. Thus the total number is given by
 
1 100
= 80850 .
2 3
Another way to obtain this same number is to recognize that to have an even sum I must
pick either three even numbers or one even number and two odd numbers. Since these two
outcomes are mutually exclusive using the rule of sum the total number of ways to pick a
even summable subset is the sum of the number of ways to select each of the previous sets.
This number is     
50 50 50
+ ,
3 1 2
where the first combination is the number of ways to select three even numbers and the
second combination product is the number of ways to select a single odd number and then
two even numbers. One can check that the sum above reduces to 80850 also.

Exercise C.1-5 (factoring a fraction from the binomial coefficients)

Using the definition of the binomial coefficient, we have the following


   
n n! n(n 1)! n n1
= = = . (4)
k k!(n k)! k(k 1)!(n 1 (k 1))! k k1

Exercise C.1-6 (factoring another fraction from the binomial coefficients)

Using the definition of the binomial coefficient, we have the following


   
n n! n(n 1)! n n1
= = = .
k (n k)!k! (n k)(n k 1)!k! nk k

Exercise C.1-7 (choosing k subsets from n by drawing subsets of size k 1)

Considering the group of n objects with one object specified as distinguished or special.
Then the number of ways to select k objects from n can be decomposed into two distinct
occurrences. The times when this special object is selected in the subset of size k and the
times when its not. When it is not selected in the subset ofsize k we are specifying our k
n1
subset elements from the n 1 remaining elements giving total subsets in this
k
case. When it is selected into the subset
 of size
 k we have to select k 1 other elements from
n1
the n1 remaining elements, giving additional subsets in this case. Summing the
k1
counts from these two occurrences we have that factorization can be written as the following
     
n n1 n1
= + .
k k k1
Exercise C.1-8 (Pascals triangle)

We have (evaluating our binomial coefficients as we place them in the table)

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
 
0
Note that the top row only has one element 1. The second row has two elements
    0
1 1
= 1, and = 1. Subsequent rows are obtained by beginning and ending with a
0 1
one and summing the values of the two binomial coefficients in the row above.

Exercise C.1-9 (sum of the integers up to n)

Expressing each side of this expression, we have that the left hand side is given by
n
X n(n + 1)
i=
i=1
2

while the right hand side is given by


 
n+1 n(n + 1)
=
2 2
since the two sides are equal we have the proven identity.

 
n
Exercise C.1-10 (maximum of as a function of k)
k

Because the binomial coefficients satisfy


   
n n
= for 0 k n
k nk
as a function of k the values of the binomial coefficients repeat once k n2 . A specific
example ofthis  can be seen in the Pascal triangle construction in Exercise C.1-8. If we can
n
show that is an increasing function of k, the k value that will maximize the binomial
k
coefficient will be the one corresponding to k n2 . If n is even this maximum will occur the
value floor( n2 ) while if n is odd this maximum will be found at floor( n2 ) and ceiling( n2 ).
 
n
All one has to do is show that is an increasing function of k, which means proving
k
the following chain of reasoning is reversible
   
n n
>
k+1 k
n! n!
>
(k + 1)!(n k 1)! (n k)!k!
(n k)! (k + 1)!
>
(n k 1)! k!
nk > k+1
n > 2k + 1
n1
k <
2
 
n
which says that is increasing as a function of k as long as k < n12
, which equals the
k
floor and ceiling expressions above if n is odd or even respectively.

Exercise C.1-11 (a product upper bounds on binomial coefficients)

We want to show that for any n 0, j 0, k 0 and j + k n that


    
n n nj
.
j+k j k
To show this using an algebraic proof, we will evaluate the left hand side of this expression,
convert it into the right hand side multiplied by a correction factor and then show that the
correction factor is less than one. To begin we have
 
n n!
=
j+k (j + k)!(n j k)!
n! j!(n j)!
=
j!(n j)! (j + k)!(n j k)!
 
n (n j)! j!k!
=
j k!(n j k)! (j + k)!
  
n n j (j(j 1)(j 2) 2 1)(k(k 1) 2 1)
=
j k (j + k)(j + k 1)(j + k 2) 21
  
n nj
Note that the top and bottom of the factor multiplying the terms both
j k
have j + k elements in their product. With out loss of generality we will assume that j k.
The product above can be written as
(j(j 1)(j 2) 2 1)(k(k 1) 2 1) j!k!
=
(j + k)(j + k 1)(j + k 2) 21 (k + j)(k + j 1) (k + 1)k!
j(j 1)(j 2) 21
= < 1,
(j + k)(j + k 1)(j + k 2) (k + 2)(k + 1)
since for every factor in the numerator, we can find a term in the denominator that is larger
than it, for example the ratio of the first product in the numerator and denominator above
satisfy
j
< 1.
j+k
As the combined correction factor (with all these ratios) is less than one, we have shown the
inequality we started with.

As a combinatorial proof, the number of ways to select j + k items from a set of n will
be smaller than if we first select j items from n, and for each of those sets select k items
from n j. That the former is a larger number can be seen by the following example where
equality does not hold. Consider the case n = 4, k = 3, and j = 1, then
    
4 4 3
=1< = 4.
4 1 3

There the number of ways to select 4 items from 4 is only one which is smaller than if we are
allowed to select 1 of the 4 items first (of which there are four ways) and then combine this
with the number of ways to select three remaining elements (of which there is only one).

Exercise C.1-12 (a algebraic upper bound on the binomial coefficients)

We desire to prove by induction that


nn
 
n
k .
k k (n k)nk

Assuming that 00 = 1, we can show that k = 0 satisfies this easily since it reduces to 1 1.
However, to begin with amore
 realistic case, to anchor our induction proof to, we start with
n
k = 1. This value gives = n for the left hand side of this expression, while the right
1
hand-side evaluates to
nn
.
(n 1)n1
This can be simplified as follows
nn nn1
 
= n
(n 1)n1 (n 1)n1
 n1
n
= n
n1
 n1
1
= n
1 n1
1
Now since we assume that n > 1, the expression 1 n
is bounded by
1
0<1 <1
n
and more specifically
1
1< 1 .
1 n

Taking positive powers of this expression (i.e. to the n 1 power) can only increase its value
and we have that  n1
1
n<n
1 n1
which provides the anchoring point from which to begin mathematical induction. Having
shown that this inequality is true for k = 1 we next proceed to assume it is true for k < k
and show that it is true for k < k + 1. To do this consider the following
 
n n!
=
k+1 (n k 1)!(k + 1)!
 
n! nk
=
(n k)!k! k + 1
  
n nk
=
k k+1
n
nn
 
n nk
k = .
k (n k)nk k + 1 k k (k + 1)(n k)nk1

Here on the last step we have used the induction hypothesis. Our induction proof will be
finished if we can show that the last expression above is less than the following
nn
.
(k + 1)k+1(n k 1)nk1

Towards this end we will show this by assuming that it is true and then through reversible
transformations reduce this expression to one that is known to be true. Since all transfor-
mation are reversible the original inequality must be true. So to begin we assume that
nn nn

k k (k + 1)(n k)nk1 (k + 1)k+1(n k 1)nk1
(k + 1)k (n k)nk1

kk (n k 1)nk1
 k  nk1
1 1
1+ 1+
k nk1

From the above if we define the function f (x) as


 x
1
f (x) = 1 +
x

The above expression becomes the following functional relationship, which if we can prove
is true, will complete the inductive proof

f (k) f (n k 1) .
2.6

2.4

2.2

1.8

f
1.6

1.4

1.2

1
0 1 2 3 4 5 6 7 8 9 10
x

Figure 1: Graphical plot showing the monotonicity of f (x) required for the inductive proof
in Exercise C.1-12.

Further assuming that f has a monotone inverse (to be discussed below) then we can apply
the inverse to this expression to obtain the region of validity for this inequality as

k nk1

or k n1
2
. For all the statements above to be valid (and our induction proof to be complete)
all one must do now is to show that f (x) has an inverse or equivalently that f (x) is monotonic
over its domain. This could be done with derivatives but rather than that Figure 1 shows a
plot of f (x) showing its monotonic behavior.

Note also from the symmetry relationship possessed by the binomial coefficients, i.e,
   
n n
=
k nk
we can extend our result above to all 0 k n.

Exercise C.1-13 (Stirlings approximate for some binomial coefficients)

We desire to show that


22n
 
2n
= (1 + O(1/n))
n n
using Stirlings approximation. From the definition of the binomial coefficients we know that
 
2n (2n)!
= .
n n! n!
Now Stirlings approximation gives an estimate of n!. Its expression is
 n n  
1
n! = 2n 1 + ( ) .
e n
Therefore substituting 2n for n we have an approximation to (2n)! given by
 2n 


2n 1
(2n)! = 4n 1 + ( ) .
e n

We also need an expression for (n!)2 , which is given by


 n 2n  2
2 1
(n!) = 2n 1 + ( )
e n
 n 2n  1

= 2n 1 + ( ) .
e n
Thus we have that
2n 2n
1 + ( n1 )
 
4n
 
2n e
= 2n
n 2n ne 1 + ( n1 )
 
 2n
1 2n 1 + ( n1 )
=
n n 1 + ( n1 )
2n
  
2 1 1
= 1 + ( ) 1 + ( )
n n n
2n
 
2 1
= 1 + ( ) .
n n
As was to be shown. In deriving this result we have made repeated use of the algebra of
order symbols.

Exercise C.1-14 (the maximum of the entropy function H())

The entropy function is given by

H() = lg() (1 ) lg(1 ) .

Remembering the definition of lg() in terms of the natural logarithm ln() as

ln(x)
lg(x) =
ln(2)

we have that the derivative of the lg() function is given by

lg(x) 1
= .
dx x ln(2)
Using this expression we can take the derivative of the binary entropy function giving
(1 )
H () = lg() + lg(1 ) +
ln(2) (1 ) ln(2)
= lg() + lg(1 ) .
When we set this equal to zero looking for an extrema we have that
lg() + lg(1 ) = 0
which has as its solution = 21 . We can check that this point is truly a maximum and not
a minimum by computing the second derivative of H(). We have that
1 1
H () = ,
ln(2) (1 ) ln(2)
1
which is negative when = 2
implying a maximum. We also have that
1 1 1
H( ) = + = 1 .
2 2 2

Exercise C.1-15 (moment summing of binomial coefficients)

Consider the binomial expansion learned in high school


n  
n
X n
(x + y) = xk y nk .
k
k=0

Taking the derivative of this expression with respect to x gives the following
n  
n1
X n
n(x + y) = kxk1 y nk ,
k
k=0

evaluating at x = y = 1, then gives


n  
n1
X n
n2 = k,
k
k=0

as was desired to be shown.

Appendix C.2 (Probability)

Exercise C.2-1 (Booles inequality)

We begin by decomposing the countable union of sets Ai i.e.


A1 A2 A3 . . . ,
into a countable union of disjoint sets Cj . Define these disjoint sets as
C1 = A1
C2 = A2 \A1
C3 = A3 \(A1 A2 )
C4 = A4 \(A1 A2 A3 )
..
.
Cj = Aj \(A1 A2 A3 Aj1 )
Then by construction
A1 A2 A3 = C1 C2 C3 ,
and the Cj s are disjoint, so that we have
X
Pr(A1 A2 A3 ) = Pr(C1 C2 C3 ) = Pr(Cj ) .
j

Since Pr(Cj ) Pr(Aj ), for each j, this sum is bounded above by


X
Pr(Aj ) ,
j

and Booles inequality is proven.

Exercise C.2-2 (more head for professor Rosencrantz)

For this problem we can explicitly enumerate our sample space and then count the number
of occurrences where professor Rosencrantz obtains more heads than professor Guildenstern.
Denoting the a triplet of outcomes from the one coin flip by Rosencrantz and the two coin
flips by Guildenstern as (R, G1 , G2 ), we see that the total sample space for this experiment
is given by
(H, H, H) (H, H, T ) (H, T, H) (H, T, T )
(T, H, H) (T, H, T ) (T, T, H) (T, T, T )
From which the only outcome where professor Rosencrantz obtains more heads than professor
Guildenstern is the sample (H, T, T ). Since this occurs once from eights possible outcomes,
Rosencrantz has a 1/8 probability of winning.

Exercise C.2-3 (drawing three ordered cards)

There are 10 9 8 = 720 possible ways to draw three cards from ten when the order of the
drawn cards matters. To help motivate how to calculate then number of sorted three card
draws possible, well focus how the number of ordered draws depends on the numerical value
of the first card drawn. For instance, if a ten or a nine is drawn as a first card there are no
possible ways to draw two other cards and have the total set ordered. If an eight is drawn
as the first card, then it is possible to draw a nine for the second and a ten for the third
producing the ordered set (8, 9, 10). Thus if an eight is the first card drawn there is one
possible sorted hand. If a seven is the first card drawn then we can have second and third
draws consisting of (8, 9), (8, 10), or a (9, 10) and have an ordered set of three cards. Once
the seven is drawn we now are looking for the number of ways to draw two sorted cards from
{8, 9, 10}. So if an seven is drawn we have three possible sorted hands. Continuing, if a six
is drawn as the first card we have possible second and third draws of: (7, 8), (7, 9), (7, 10),
(8, 9), (8, 10), or (9, 10) to produce an ordered set. Again we are looking for a way to draw
two sorted cards from a list (this time {7, 8, 9, 10}).
After we draw the first card an important subcalculation is to compute the number of ways
to draw two sorted cards from a list. Assuming we have n ordered items in our list, then
we have n ways to draw the first element and n 1 ways to draw the second element giving
n(n1) ways to draw two elements. In this pair of elements one ordering result in a correctly
sorted list (the other will not). Thus half of the above are incorrectly ordered what remains
are
n(n 1)
N2 (n) =
2
The number of total ways to draw three sorted cards can now be found. If we first draw an
eight we have two cards from which to draw the two remaining ordered cards in N2 (2) ways.
If we instead first drew a seven we have three cards from which to draw the two remaining
ordered cards in N2 (3) ways. If instead we first drew a six then we have four cards from
which to draw two ordered cards in N2 (4) ways. Continuing, if we first draw a one, we have
nine cards from which to draw two ordered cards in N2 (9) ways. Since each of these options
is mutually exclusive the total number of ways to draw three ordered cards is given by
9 9
X X n(n 1)
N2 (3) + N2 (4) + N2 (5) + + N2 (9) = N2 (n) = = 120 .
n=2 n=2
2

Finally with this number we can calculate the probability of drawing three ordered cards as
120 1
= .
720 6

Exercise C.2-4 (simulating a biased coin)

Following the hint, since a < b, the quotient a/b is less than one. If we express this number
in binary we will have an (possibly infinite) sequence of zeros and ones. The method to
determine whether to return a biased heads (with probability a/b) or a biased tails
(with probability (ba)/b) is best explained with an example. To get a somewhat interesting
binary number, lets assume an example where a = 76 and b = 100, then our ratio a/b is 0.76.
In binary that has a representation given by (see the Mathematica file exercise C 2 4.nb)

0.76 = 0.11000010100011110112

We then begin flipping our unbiased coin. To a head result we will associate a one and to
a tail result we shall associate a zero. As long as the outcome of the flipped coin matches
the sequence of ones and zeros in the binary expansion of a/b, we continue flipping. At the
point where the flips of our unbiased coins diverges from the binary sequence of a/b we stop.
If the divergence produces a sequence that is less than the ratio a/b we return this result by
returning a biased head result. If the divergence produces a sequence that is greater than
the ratio a/b we return this result by returning a biased tail result. Thus we have used
our fair coin to determine where a sequence of flips falls relative to the ratio of a/b.

The expected number of coin flips to determine our biased result will be the expected number
of flips required until the flips from the unbiased coin dont match the sequence of zeros and
ones in the binary expansion of the ratio a/b. If we assume that a success is when our
unbiased coin flip does not match the digit in the binary expansion of a/b. The for each
flip a success can occur with probability p = 1/2 and a failure can occur with probability
q = 1 p = 1/2, we have that the number of flips n needed before a success is a geometric
random variable with parameter p = 1/2. This is that
P {N = n} = q n1 p .
So that the expected number of flips required for a success is then the expectation of the
geometric random variable and is given by
1
E[N] = = 2,
p
which is certainly O(1).

Exercise C.2-5 (closure of conditional probabilities)

Using the definition of conditional probability given in this section we have that
P {A B}
P {A|B} = ,
P {B}
so that the requested sum is then given by

P {A B} P {A B}
P {A|B} + P {A|B} = +
P {B} P {B}
P {A B} + P {A B}
=
P {B}
Now since the events A B and A B are mutually exclusive the above equals
P {(A B) (A B)} B}
P {(A A) P {B}
= = = 1.
P {B} P {B} P {B}

Exercise C.2-6 (conditioning on a chain of events)

This result follows for the two set case P {A B} = P {A|B}P {B} by grouping the sequence
of Ai s in the appropriate manner. For example by grouping the intersection as
A1 A2 An1 An = (A1 A2 An1 ) An
we can apply the two set result to obtain
P {A1 A2 An1 An } = P {An |A1 A2 An1 } P {A1 A2 An1 } .
Continuing now to peal An1 from the set A1 A2 An1 we have the second probability
above equal to
P {A1 A2 An2 An1 } = P {An1|A1 A2 An2 }P {A1 A2 An2 } .
Continuing to peal off terms from the back we eventually obtain the requested expression
i.e.

P {A1 A2 An1 An } = P {An |A1 A2 An1 }


P {An1 |A1 A2 An2 }
P {An2 |A1 A2 An3 }
..
.
P {A3 |A1 A2 }
P {A2 |A1 }
P {A1 } .

Exercise C.2-7 (pairwise independence does not imply independence)

Note: As requested by the problem I was not able to find a set of events that are pairwise
independent but such that no subset k > 2 of them are mutually independent. Instead I
found a set of events that are all pairwise independent but that are not mutually independent.
If you know of a solution to the former problem please contact me.

Consider the situation where we have n distinct people in a room. Let Ai,j be the event
that person i and j have the same birthday. We will show that any two of these events are
pairwise independent but the totality of events Ai,j are not mutually independent. That is
we
 desire
 to show that the two events Ai,j and Ar,s are independent but the totality of all
n
events are not independent. Now we have that
2

1
P (Ai,j ) = P (Ar,s ) = ,
365
since for the specification of either one persons birthday the probability that the other person
will have that birthday is 1/365. Now we have that
  
1 1 1
P (Ai,j Ar,s ) = P (Ai,j |Ar,s )P (Ar,s ) = = .
365 365 3652

This is because P (Ai,j |Ar,s ) = P (Ai,j ) i.e. the fact that persons r and s have the same
birthday has no effect on whether the persons i and j have the same birthday. This is true
even if one of the people in the pairs (i, j) and (r, s) is the same. When we consider the
intersection of all the sets Ai,j , the situation changes. This is because the event (i,j) Ai,j
(where the intersection is over all pairs (i, j)) is the event that every pair of people have the
same birthday, i.e. that everyone considered has the same birthday. This will happen with
probability  n1
1
,
365
while if the events Ai,j were independent the required probability would be

  n   n(n1)
1 1

2
Y 2
P (Ai,j ) = = .
365 365
(i,j)

 
n
Since 6= n 1, these two results are not equal and the totality of events Ai,j are not
2
independent.

Exercise C.2-8 (conditional but not independence)

Consider the situation where we have to coins. The first coin C1 is biased and has probability
p of landing heads when flipped where p > 1/2. The second coin C2 is fair and has probability
of landing heads 1/2. For our experiment one of the two coins will be selected (uniformly and
at random) and presented to two people who will each flip this coin. We will assume that
the coin that is selected is not known. Let H1 be the event that the first flip lands heads,
and let H2 be the event that the second flip lands heads. We can show that the events H1
and H2 are not independent by computing P (H1 ), P (H2 ), and P (H1 , H2 ) by conditioning
on the coin selected. We have for P (H1 )

P (H1) = P (H1 |C1 )P (C1) + P (H1 |C2 )P (C2)


1 11
= p +
2 22
1 1
= (p + ) ,
2 2
Here C1 is the event that we select the first (biased) coin while C2 is the event we select the
second (unbiased) coin. In the same way we find that
1 1
P (H2 ) = (p + ) ,
2 2
while P (H1, H2 ) is given by

P (H1, H2 ) = P (H1 , H2 |C1 )P (C1) + P (H1 , H2 |C2 )P (C2)


1 11
= p2 +
2 42
1 2 1
= (p + ) .
2 4
The events H1 and H2 will only be independent if P (H1 )P (H2) = P (H1, H2 ) or
 2
1 1 1 1
p+ = (p2 + ) .
4 2 2 4

or simplifying this result equality only holds if p = 1/2 which we are assuming is not true.
Now let event E denote the event that we are told that the coin selected and flipped by both
parties is the fair one, i.e. that event C2 happens. Then we have
1 1
P (H1 |E) = and P (H2 |E) =
2 2
1
P (H1 , H2 |E) = .
4
Since in this case we do have P (H1 , H2 |E) = P (H1|E)P (H2|E) we have the required condi-
tional independence. Intuitively, this result makes sense because once we know that the coin
flipped is fair we expect the result of each flip to be independent.

Exercise C.2-9 (the Monte-Hall problem)

Once we have selected a curtain we are two possible situations we might find ourself in. The
first situation A, is where we have selected the curtain with the prize behind it or situation
B where we have not selected the curtain with the prize behind it. The initial probability
of event A is 1/3 and that of event B is 2/3. We will calculate our probability of winning
under the two choices of actions. The first is that we choose not to switch curtains after the
emcee opens a curtain that does not cover the prize. The probability that we win, assuming
the no change strategy, can be computed by conditioning on the events A and B above as

P (W ) = P (W |A)P (A) + P (W |B)P (B) .

Under event A and the fact that we dont switch curtains we have P (W |A) = 1 and
P (W |B) = 0, so we see that P (W ) = 1/3 as would be expected. If we now assume that
we follow the second strategy where by we switch curtains after the emcee revels a curtain
behind which the prize does not sit. In that case P (W |A) = 0 and P (W |B) = 1, since in
this strategy we switch curtains. The the total probability we will is given by
2 2
P (W ) = 0 + 1 = ,
3 3
since this is greater than the probability we would win under the strategy were we dont
switch this is the action we should take.

Exercise C.2-10 (a prison delima)

I will argue that X has obtained some information from the guard. Before asking his question
the probability of event X (X is set free) is P (X) = 1/3. If prisoner X is told that Y (or Z
in fact) is to be executed, then to determine what this implies about the event X we need
to compute P (X|Y ). Where X, Y , and Z are the events that prisoner X, Y , or Z is to be
set free respectively. Now from Bayes rule

P (Y |X)P (X)
P (X|Y ) = .
P (Y )
We have that P (Y ) is given by
1 1 2
P (Y ) = P (Y |X)P (X) + P (Y |Y )P (Y ) + P (Y |Z)P (Z) = +0+ = .
3 3 3
So the above probability then becomes

1(1/3) 1 1
P (X|Y ) = = > .
2/3 2 3

Thus the probability that prisoner X will be set free has increased and prisoner X has
learned from his question.

proof of the cumulative summation formula for E[X] (book notes page 1109)

We have from the definition of the expectation that



X
E[X] = iP {X = i} .
i=0

expressing this in terms of the the complement of the cumulative distribution function
P {X i} gives E[X] equal to

X
i(P {X i} P {X i + 1}) .
i=0

Using the theory of difference equations we write the difference in probabilities above in
terms of the operator defined on a discrete function f (i) as

g(i) g(i + 1) g(i) ,

giving

X
E[X] = ii P {X i} .
i=0

No using the discrete version of integration by parts (demonstrated here for two discrete
functions f and g) we have

X
X
f (i)g(i) = f (i)g(i)|
i=1 f (i)g(i) ,
i=0 i=1

gives for E[X] the following



X
E[X] = iP {X i}|
i=1 + P {X i}
i=1

X
= P {X i} .
i=1
1 2 3 4 5 6
1 (2,1) (3,2) (4,3) (5,4) (6,5) (7,6)
2 (2,2) (4,2) (5,3) (6,4) (7,5) (8,6)
3 (4,3) (5,3) (6,3) (7,4) (8,5) (9,6)
4 (5,4) (6,4) (7,4) (8,4) (9,5) (10,6)
5 (6,5) (7,5) (8,5) (9,5) (10,5) (11,6)
6 (7,6) (8,6) (9,6) (10,6) (11,6) (12,6)

Table 2: The possible values for the sum (the first number) and the maximum (the second
number) observed when two die are rolled.

which is the desired sum. To see this another way we can explicitly write out the summation
given above and cancel terms as in

X
E[X] = i(P {X i} P {X i + 1})
i=0
= 0 + P {X 1} P {X 2}
+ 2P {X 2} 2P {X 3}
+ 3P {X 3} 3P {X 4} + . . .
= P {X 1} + P {X 2} + P {X 3} + . . . ,

verifying what was claimed above.

Appendix C.3 (Discrete random variables)

Exercise C.3-1 (expectation of the sum and maximum of two die)

We will begin by computing all possible sums and maximum that can be obtained when we
roll two die. These numbers are computed in table 2, where the row corresponds to the first
die and the column corresponds to the second die. Since each roll pairing has a probability
of 1/36 of happening we see that the expectation of the sum S is given by
           
1 2 3 4 5 6
E[S] = 2 +3 +4 +5 +6 +7
36 36 36 36 36 36
         
5 4 3 2 1
+ 8 +9 + 10 + 11 + 12
36 36 36 36 36
= 6.8056 .

While the expectation of the maximum M is given by a similar expression


           
1 3 5 7 9 11
E[M] = 1 +2 +3 +4 +5 +6
36 36 36 36 36 36
= 4.4722 .
Exercise C.3-2 (expectation of the index of the max and min of a random array)

Since the array elements are assumed random the maximum can be at any of the n indices
with probability 1/n. Thus if we define X to be the random variable representing the location
of the maximum of our array we see that the expectation of X is given by
     
1 1 1
E[X] = 1 +2 + +n
n n n
n  
1X 1 n(n + 1)
= k=
n k=1 n 2
n+1
= .
2
The same is true for the expected location of the minimum.

Exercise C.3-3 (expected cost of playing a carnival game)

Define X to be the random variable denoting the payback from one play of the carnival
game. Then the payback depends on the possible outcomes after the player has guessed a
number. Let E0 be the event that the players number does not appear on any die, E1 the
event that the players number appears on only one of the three die, E2 the event that the
players number appears on only two of the die, and finally E3 the event that the players
number appears on all three of the die. The the expected payback is given by
E[X] = P (E0 ) + P (E1 ) + 2P (E2 ) + 3P (E3 ) .
We now compute the probability of each of the events above. We have
 3
5
P (E0 ) = = 0.5787
6
   2
1 5
P (E1 ) = 3 = 0.3472
6 6
1 1 5
P (E2 ) = 3 = 0.0694
6 6 6
1
P (E3 ) = 3 = 0.0046 .
6
Where the first equation expresses the fact that each individual die will not match the
players selected die with probability of 5/6, so the three die will not match the given die
with probability (5/6)3 . The other probabilities are similar. Using these to compute the
expected payoff using the above formula gives
17
E[X] = = 0.0787 .
216
To verify that these numbers are correct in the Matlab file exercise C 3 3.m, a Monte-Carlo
simulation is developed verifying these values. This function can be run with the command
exercise C 3 3(100000).
Exercise C.3-4 (bounds on the expectation of a maximum)

We have for E[max(X, Y )] computed using the joint density of X and Y that
XX
E[max(X, Y )] = max(x, y)P {X = x, Y = y}
x y
XX
(x + y)P {X = x, Y = y} ,
x y

since X and Y are non-negative. Then using the linearity of the above we have
XX XX
E[max(X, Y )] xP {X = x, Y = y} + yP {X = x, Y = y}
x y x y
X X
= xP {X = x} + yP {Y = y}
x y
= E[X] + E[Y ] ,

which is what we were to show.

Exercise C.3-5 (functions of independent variables are independent)

By the independence of X and Y we know that

P {X = x, Y = y} = P {X = x}P {Y = y} .

But by definition of the random variable X has a realization equal to x then the random
variable f (X) will have a realization equal to f (x). The same statement hold for the random
variable g(Y ) which will have a realization of g(y). Thus the above expression is equal to
(almost notationally)

P {f (X) = f (x), g(Y ) = g(y)} = P {f (X) = f (x)}P {g(Y ) = g(y)}

Defining the random variable F by F = f (X) (an instance of this random variable f ) and
the random variable G = g(Y ) (similarly and instance of this random variable g) the above
shows that
P {F = f, G = g} = P {F = f }P {G = g}
or
P {f (X) = f, g(Y ) = g} = P {f (X) = f }P {g(Y ) = g} ,
showing that f (X) and g(Y ) are independent as requested.

Exercise C.3-6 (Markovs inequality)

To prove that
E[X]
P {X t} ,
t
is equivalent to proving that
E[X] tP {X t} .
To prove this first consider the expression for E[X] broken at t i.e.
X
E[X] = xP {X = x}
x
X X
= xP {X = x} + xP {X = x} .
x<t xt
P
But since X is non-negative we can drop the expression x<t xP {X = x} from the above
and obtain a lower bound. Specifically we have
X
E[X] xP {X = x}
xt
X
t P {X = x}
xt
= tP {X t} ,

or the desired result.

Exercise C.3-7 (if X(s) X (s) then P {X t} P {X t})

Lets begin by defining two sets At and Bt as follows

At = {s S : X(s) t}
Bt = {s S : X (s) t} .

Then lets consider an element s Bt . Since s is in Bt we know that X ( s) > t. From the
assumption on X and X we know that X( s) X (
s) t, and s must also be in At . Thus
the set Bt is a subset of the set At . We therefore have that
X X
P {X t} = P {s} P {s} = P {X t} ,
sAt sBt

and the desired result is obtained.

Exercise C.3-8 (E[X 2 ] > E[X]2 )

From the calculation of the variance of the random variable X we have that

Var(X) = E[(X E[X])2 ] > 0 ,

since the square in the expectation is always a positive number. Expanding this square we
find that
E[X 2 ] E[X]2 > 0 .
Which shows on solving for E[X 2 ] that
E[X 2 ] > E[X]2 ,
or that the expectation of the square of the random variable is larger than the square of
the expectation. This make sense because if X where to take on both positive and negative
values in computing E[X]2 the expectation would be decreased by X taking on instances of
both signs. The expression E[X 2 ] would have no such difficulty since X 2 is aways positive
regardless of the sign of X.

Exercise C.3-9 (the variance for binary random variables)

Since X takes on only value in {0, 1}, lets assume that


P {X = 0} = 1 p
P {X = 1} = p .
Then the expectation of X is given by E[X] = 0(1 p) + 1p = p. Further the expectation
of X 2 is given by E[X 2 ] = 0(1 p) + 1p = p. Thus the variance of X is given by
Var(X) = E[X 2 ] E[X]2
= p p2 = p(1 p)
= E[X](1 E[X])
= E[X] E[1 X] .
Where the transformation 1 E[X] = E[1 X] is possible because of the linearity of the
expectation.

Exercise C.3-10 (the variance for aX)

From the suggested equation we have that


Var(aX) = E[(aX)2 ] E[aX]2
= E[a2 X 2 ] a2 E[X]2
= a2 (E[X 2 ] E[X]2 )
= a2 Var(X) ,
by using the linearity property of the expectation.

Appendix C.4 (The geometric and binomial distributions)

an example with the geometric distribution (book notes page 1112)

All the possible outcomes for the sum on two die are given in table 2. There one sees that the
sum of a 7 occurs along the right facing diagonal (elements (6, 1), (5, 5), (4, 3), (3, 4), (2, 5), (1, 6)),
while the sum of 11 occurs for the elements (6, 5), (5, 6). The the probability we roll a 7 or
an 11 is given by
6 2 8 2
p= + = = .
36 36 36 9
if we take this as the probability of success then the remaining results from the book follow.

Exercise C.4-1 (the closure property for the geometric distribution)

The geometric distribution gives the probability our first success occurs at trail numbered k
when each trial has p as a probability of success. It has a distribution function given by
P {X = k} = p(1 p)k1 = pq k1 .
Where we have defined q = 1 p. If we sum this probability distribution for all possible
location of the first success we obtain

X pX k
p(1 p)k1 = q
k=1
q k=1

!
p X
= qk 1
q k=0
 
p 1
= 1
q 1q
 
p 1
= 1
q p
 
p 1p
= = 1,
q p
as we were to show.

Exercise C.4-2 (average number of times to obtain three heads and tails)

Let one trial consist of flipping six coins. Then we consider a success when we have obtained
6
three head and three tails. Thussince  there are 2 possible outcomes of six flips when the
6
flips are ordered there are then the probability of success (p) for this experiment
3
is given by  
6
3 20
p= 6
= = 0.3125 .
2 64
Since the number of trials needed to obtain a success is a geometric distribution we have
that the average number of times we must perform this experiment is given by the average
for a geometric distribution with probability of success p or
1 1
= = 3.2 .
p 0.3125
Exercise C.4-3 (an equality with the binomial distribution)

Using the definition of b(k; n, p) we have that


 
n
b(k; n, p) = pk (1 p)nk .
k
   
n n
Since = the above can be written as
k nk
 
n
b(k; n, p) = (1 p)nk pk .
nk
Defining q = 1 p we see the right hand side of the above is equal to
 
n
q nk (1 q)k = b(n k; n, q) ,
nk
and the desired result is shown.

Exercise C.4-4 (the maximum of the binomial coefficient)

From the discussion in the text the binomial coefficient has a maximum at the integer k
that lies in the range np q < k < (n + 1)p. To evaluate the approximate maximum of the
binomial coefficient we will evaluate it at k = np which is certainly between the two limits
np q and (n + 1)p. Our binomial coefficient evaluated at its approximate maximum k = np
is given by
 
n
b(np; n, p) = pnp (1 p)nnp
np
n!
= pnp (1 p)nq
(n np)!(np)!
n!
= pnp q nq .
(nq)!(np)!
where we have introduced q = 1 p into the above to simplify the notation. Using Stirlings
approximation for n! given by
 n n  
1
n! = 2n 1 + ( ) ,
e n
we can simplify the factorial expression above (and dropping the order symbols ) we have
 nq  np
n!  n n 1 e 1 e
2n
(nq)!(np)! e 2nq nq 2np np
1/2
nn

1 n
=
2 (nq)(np) (nq)nq (np)np
 1/2  n
1 1 1
= .
2 nqp q q pp
upon multiplying the above by pnp q nq we find that
 1/2
1
b(np; n, p) ,
2npq
as we were to show.

Exercise C.4-5 (the limiting probability of no successes)

The probability of no successes in a sequence of n Bernoulli trials with (probability of success


p = 1/n) is given by b(0; n, 1/n). This is equal to
   0  n
n 1 1
b(0; n, 1/n) = 1
0 n n
 n
1
= 1
n
Remembering a famous limit from calculus
 x n
lim 1 + = ex ,
x+ n
we see that for large n the probability b(0; n, 1/n) is approximately e1 . The probability of
at least one success is given by b(1; n, 1/n). This is equal to
   1  n1
n 1 1
b(1; n, 1/n) = 1
1 n n
  n1
1 1
= n 1
n n
 n1
1
= 1
n
 n
1 1
=  1
1 n1 n
 n
1
1 as n + .
n

Using the limiting argument above we have this probability equal to e1 as n goes to infinity.

Exercise C.4-6 (the probability of obtaining the same number of heads)

For a total of 2n flips we have 22n = 4n possible sequences of heads and tails in 2n flips.
Let the first n of these correspond to the flips of professor Rosencrantz and the remaining
n corresponds to those of professor Guildenstern. Following the hint in the book, we will
call a success for professor Rosencrantz when his flip lands heads and a success for professor
Guildenstern when his flip lands tails. Then both professors will obtain the same number
of heads if say professor Rosencrantz has k successes while professor Guildenstern has n k
successes. Thus the number of sequences (from our 4n ) that have the same number of heads
for both professors is an equivalent problem to selecting k + (n k) = n total locations
from among 2n possible and declaring these to be the locations of the successes for both
professors. This means that if a success is placed before the n + 1th flip it is considered to be
a success for professor Rosencrantz and denotes a head (the remaining flips for Rosencrantz
are then all tails). If a success falls after the nth flip it is considered to be a success for
professor Guildenstern and is considered to be a tail (the remaining flips for Guildenstern
are considered
  to be all heads). The number of sequences with n total successes is given by
2n
and so the probability of obtaining the same number of heads is given by
n
 
2n
n
,
4n
as claimed. Using the result from Exercise C.1-13 which derives the approximate

4n
   
2n 1
= 1 + O( ) .
n n n

we can simplify the probability of obtaining the same number of heads and find that is is
approximately equal to  
1 1
1 + O( ) .
n n
Another way to approach this problem is to explicitly sum the probability that professor
Rosencrantz has k successes while professor Guildenstern has nk successes. The probability
that both these events happen (since they are independent) is given by the product of the
appropriate binomial distribution i.e.

b(k; n, 1/2)b(n k; n, 1/2) .

So the total probability of that the two professors get the same number of heads is given by
the sum of that probability for all possible ks (k = 0 to k = n) or
n
X
b(k; n, 1/2)b(n k; n, 1/2) .
k=0

This expression simplifies in the obvious ways


n
X n
X
b(k; n, 1/2)b(n k; n, 1/2) = b(k; n, 1/2)2
k=0 k=0
n  2  2n
X n 1
=
k 2
k=0
n  2
1 X n
= n .
4 k=0 k
In the above we have used the symmetry of the binomial distribution with respect to k and
n k, i.e. b(k; n, 1/2) = b(n k; n, 1/2), which a special case of the result shown in Exercise
C.4-3 above. Equating these two results we have a nice combinatorial identity
n  2  
X n 2n
= ,
k n
k=0

as claimed.

Exercise C.4-7 (the entropy bound on the binomial distribution)

From the binomial bound derived in Appendix C.1 (also see the notes above that go with
that section) we have that  
n n
2nH( k ) .
k
Using this expression we can immediately bound b(k; n, 1/2) as
   k  nk
n 1 1
b(k; n, 1/2) =
k 2 2
   n
n 1
=
k 2
 n
n 1
2nH( k )
2
n
= 2nH( k )n ,

which is the desired upper bound on b(k; n, 1/2).

Exercise C.4-8 (sums of Bernoulli random variables with different values of p)

Since X is a random variable representing the total number of success in n Bernoulli trials
(with each trial having pi as its probability of success) we can explicitly express X as the
sum of n indicator random variables Ii as
n
X
X= Ii .
i=1

Here where Ii is one if the ith Bernoulli trial is a success and zero otherwise. Then since
the definition of P {X < k} means the sum of the probability that X takes the values
0, 1, . . . , k 1 or
k1
X
P {X < k} = P {X = i} ,
i=0

the probability we are attempting to bound is given in terms of equality probabilities i.e.
expressions like P {X = i}. Now for the random variable X to be exactly i means that only
i of the Bernoulli trials were a success (no more and no less) and the remaining trials were a
failure. Thus if we select a subset of size i from the n total Bernoulli random variables, the
above probability is expressed as the sum over all such subsets of size i i.e.
X
P {X = i} = pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln ) . (5)

Here the sum is over all possible subsets of size i from n and the indices li select which of
the i Bernoulli indicator variables from n were successful. Now since pi p it follows that
1 pi 1 p and thus using these for each factor in the product we have that the term in
the sum above is bounded as

pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln ) pi (1 p)ni , (6)


 
n
Since there are total terms in the sum above we see that
i
 
n
P {X = i} pi (1 p)ni = b(i; n, p) .
i

Thus using this we have just shown that


k1
X k1
X
P {X < k} = P {X = i} b(i; n, p) ,
i=0 i=0

which is the desired result.

Exercise C.4-9 (a lower bound on our success)

We can work this exercise in much the same way as the previous exercise C.4-8. Here we
can still write P {X = i} in the form as given by Equation 5. Rather than use a single value
of p such that p pi for all i we now have several pi where pi pi and thus Equation 6 in
this case becomes

pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln ) pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln ) .

Thus
X
P {X = i} = pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln )
X
pl1 pl2 pli (1 pli+1 )(1 pli+2 ) (1 pln ) = P {X = i} .

The cumulative probabilities now follow. We have


n
X n
X

P {X k} = P {X = i} P {X = i} = P {X k} ,
i=k i=k

which is the desired result.


Appendix C.5 (The tails of the binomial distribution)

Exercise C.5-1 (flip n tails or obtain fewer than n heads)

We know that the probability of obtaining n failures when flipping a fair coin is given by
 n
1
2

This is to be compared to the probability of flipping fewer than n heads when we flip our
fair coin 4n times or
n1
X
b(i; 4n, 1/2)
i=0

From Corollary C.5 we have that (with X the number of success obtained in our 4n flips)
that
n1
X
P {X < n} = b(i; 4n, 1/2) < b(n; 4n, 1/2) .
i=0

Now for b(n; 4n, 1/2) we have


   n  4nn
4n1 1
b(n; 4n, 1/2) =
n 2 2
 4n
4n! 1
=
3n!n! 2
 4n
(4n)(4n 1)(4n 2)(4n 3) (3n + 2)(3n + 1) 1
= .
n! 2

Since the numerator in the above has n factors we can break this factor up into n products
(each of which is less than 4) like the following
       
4n 4n 1 4n 2 4n 3 3n + 2 3n + 1
.
n n1 n2 n3 2 1

Therefore since each term in the above is bounded by 4 and there are n of them we can
further bound b(n; 4n, 1/2) as follows
 4n  n
n 1 1
b(n; 4n, 1/2) < 4 = .
2 4

Thus since
n1  n  n
X 1 1
b(i; 4n, 1/2) < < ,
i=0
4 2
we see that obtaining fewer than n heads in 4n flips of a fair coin is less likely then obtaining
no heads when flipping a fair coin n times.
Exercise C.5-2 (bounds on the right tail of the binomial distribution)

We begin by proving Corollary C.6 which claims that given a sequence of n Bernoulli trials
each with probability p of success that
n
X (n k)p
P {X > k} = b(i; n, p) < b(k; n, p) .
i=k+1
k np
To prove this lets first consider the ratio b(i + 1; n, p)/b(i; n, p) which is given by
 
n
pi+1 (1 p)ni1
b(i + 1; n, p) i+1
=  
b(i; n, p) n
pi (1 p)ni
i
 
ni p
= .
i+1 1p
Thus (since we assume that i is taken between k and n i.e. that k < i < n) we have
  
b(i + 1; n, p) nk p
.
b(i; n, p) k+1 1p
Defining x to be the above expression we see that x < 1 through the following arguments
  
n np p
x <
np + 1 1p
n(1 p)p np
= =
(np + 1)(1 p) np + 1
np np
< < = 1.
np + 1 np
Now using the ratio above and the definition of x we have that b(i + 1; n, p) is bounded by
b(i; n, p) as
b(i + 1; n, p) < xb(i; n, p) .
In the same way, b(i + 2; n, p) is bounded by b(i; n, p) as
b(i + 2; n, p) < xb(i + 1; n, p) < x2 b(i; n, p) .
Continuing this iteration scheme for i + 3, i + 4, we see that the probability X > k (the
right tail probability) is bounded above by
Xn
b(i; n, p) < xb(k; n, p) + x2 b(k; n, p) + + xn b(k; n, p) .
i=k+1

This can be further manipulated (by summing to infinity) as follows


Xn n
X
b(i; n, p) < b(k; n, p) xi
i=k+1 i=1
X
< b(k; n, p) xi
i=1
 
x
= b(k; n, p) .
1x
Remembering the definition of x we can compute that
x (n k)p
= ,
1x 1 p + k np
(nk)p
which is itself less than knp
so we can finally conclude that

X (n k)p
b(i; n, p) b(k; n, p) ,
i=k+1
k np
as we were asked to show.

We next prove Corollary C.7 which is the statement that given a sequence of n Bernoulli
trials each with probability p of being a success and a specific number of success k in the
right tail of our distribution ( np+n
2
< k < n) that the probability of obtaining more than k
success is less than one half the probability of obtaining more than k 1 success. This is
really a statement that as we require having more and more successes from our n Bernoulli
trials the probabilities decrease geometrically (with rate 1/2). We will begin by showing that
the coefficient of b(k; n, p) in Corollary C.6 is less than one. We have since np+n
2
<k<n
that
n np+n
   
nk 2
p < np+n p = p < 1.
k np 2
np
Thus from Corollary C.6 we have that
Xn
P {X > k} = b(i; n, p) < b(k; n, p) ,
i=k+1

or equivalently that
b(k; n, p)
Pn > 1.
i=k+1 b(i; n, p)
Now consider the ratio of P {X > k} to P {X > k 1}
Pn
P {X > k} b(i; n, p)
= Pi=k+1n
P {X > k 1} i=k b(i; n, p)
Pn
i=k+1 b(i; n, p)
=
b(k; n, p) + ni=k+1 b(i; n, p)
P

1
= b(k;n,p)
1 + Pn b(i;n,p)
i=k+1

1 1
< = ,
1+1 2
and the desired result is proven.

Exercise C.5-3 (upper bounds on a geometric sum)

a
Let a > 0 be given, and define p = a+1
< 1, then
a 1
q = 1p = 1 = .
a+1 a+1
 
n
Now consider the pq product found in the binomial coefficient b(i; n, p) = pi q ni , i.e.
i
pi q ni . With the definition given above for p and q we have
i  ni
ai

i ni a 1
pq = = .
a+1 a+1 (a + 1)n

From this we see that ai = (a + 1)n pi q ni and thus our desired sum is given by
k1   k1  
X n i n
X n
a = (a + 1) pi q ni .
i i
i=0 i=0

Which can be seen as the left tail of the binomial distribution for which we have developed
bounds for in the text. Specifically if X is a binomial random variable (with parameters
(n, p)) then using the bounds that
k1
X kq
P {X < k} = b(i; n, p) < b(k; n, p) ,
i=0
np k

the above becomes


k1 1

X a k a+1 a
b(i; n, ) a
 b(k; n, )
i=0
a+1 n a+1 k a+1
k a
= b(k; n, ).
na k(a + 1) a+1

Which gives in summary (including the factor (a + 1)n ) then that


k1  
X n k a
ai (a + 1)n b(k; n, ),
i na k(a + 1) a + 1
i=0

as we were requested to show.

Exercise C.5-4 (an upper bound on a geometric like sum)

Consider the sum we are asked to study


k1
X
pi q ni .
i=0
 
n
Since 1 for i = 0, 1, 2, , n the above sum is less than or equal to
i

k1   k1
X n i ni
X
pq = b(i; n, p) ,
i
i=0 i=0
which by Theorem C.4 is bounded above by
 
kq
b(k; n, p) .
np k

From Lemma C.1 we can further bound the individual binomial coefficient b(k; n, p) as
 np k  nq nk
b(k; n, p) .
k nk

Thus incorporating each of these bounds we have that


k1    nk
X
i ni kq np k nq
pq < ,
i=0
np k k nk

as we were requested to show.

Exercise C.5-5 (bounds on the number of failures)

We begin by defining the random variable Y to be the number of failures in n Bernoulli


trials where the probability of success for each trial is pi . Then in terms of X (the number
of successes in these n Bernoulli trials) we have that Y = n X, since each success is not a
failure and vice versa. This expression simply states that if you know the number of success
(failures) in a sequence of n Bernoulli trials it is easy to calculate the number of failures
(successes). Taking the expectation of this expression and remembering that we defined
as = E[X], we see that E[Y ] = n E[X] = n . Now applying Theorem C.8 to the
random variable Y we have that
 r
E[Y ]e
P {Y E[Y ] r} .
r

Writing the above expression in terms of X and we have


 r
(n )e
P {(n X) (n ) r} .
r
or  r
(n )e
P { X r} ,
r
the desired result.

To show the second identity, we will apply Corollary C.9 to the random variable Y , but
in this case the probability of success for each Bernoulli trial is a constant p. Thus the
probability of failure in each Bernoulli trial is also a constant q = 1 p. We thus obtain
(since E[Y ] = nq)  nqe r
P {Y nq r} .
r
Again using the fact that Y = n X to write the above expression in terms of X we find
 nqe r
P {n X nq r} ,
r
or  nqe r
P {n(1 q) X r} ,
r
or  nqe r
P {np X r} ,
r
the desired result.

Exercise C.5-6 (an exponential bound on the right tail)

Note: I was not able to prove the inequality


2 /2
pi eqi + qi epi e ,

as suggested in the text. If anyone has such a proof please contact me.

Using the notation in the text we have that (by using Markovs inequality)

P {X r} E[e(X) ]er .

Since X is the number of success in n independent Bernoulli trials X = ni=1 Xi the expec-
P
tation of the exponential can be written as the product of the individual indicator random
variables Xi as
Yn
(X)
E[e ]= E[e(Xi pi ) ] .
i=1

The explicit expectation of each term in the product is easily computed using the definition
of expectation and gives
E[e(Xi pi ) ] = pi eqi + qi epi .
2 /2
If we now assume that pi eqi + qi epi e , then the product expectation can be written
as n
2 /2 2 /2
Y
(X)
E[e ] e = en .
i=1

so that we can bound P {X r} as


2 /2 2 /2)
P {X r} en er = e(rn .

To compute the tightest possible upper bound on this probability we can minimize the
right hand side of this expression with respect to . This is equivalent to maximizing the
expression r n2 /2 with respect to . Taking the derivative of this expression and
setting it equal to zero gives
r n = 0 ,
which has = r/n as its solution. The second derivative of r n2 /2 with respect to
begin negative imply that this value of corresponds to a maximum. The value of this
quadratic at this maximal is given by

r n r2 r2
r = .
n 2 n2 2n
This result intern implies that we have an upper bound on P {X r} given by
r2
P {X r} e 2n ,

as we were required to show.

Exercise C.5-7 (minimizing the upper bound in Markovs inequality)

The equation C.45 is given by

P {X r} exp(e r) .

If we consider the right-hand side of this expression to be an function of , we can find the
that minimizes this function by taking the first derivative and setting it equal to zero. We
find that the first derivative is given by
d
exp(e r) = exp(e r) (e r) .
d
Which when we set this equal to zero and solve for gives
r
= ln( ) .

We can check that this point is indeed a minimum of our right-hand side by computing the
sign of the second derivative at that point. The second derivative is given by

d2
2
exp(e r) = exp(e r)(e r)2 + exp(e r)(e )
d
= exp(e r)(2e2 2re + r 2 + e )
= exp(e r)(2e2 (2r 1)e + r 2 ) .

Evaluating this expression at = ln(r/) (and ignoring the exponential factor which does
not affect the sign of the second derivative) gives
 2
2 r
(2r 1)r + r 2 = r 2 2r 2 + r + r 2 = r > 0 .
2

Proving that for = ln(r/) the expression exp(e r) is a minimum.


Problem C-1 (Balls and bins)

Part (a): We have b choices for the location of the first ball, b choices for the location of
the second ball, b choices for the location of the third ball and so on down to b choices for
the n-th ball. Since the balls are distinguishable each of these placements represent different
configurations. Thus the total number of possible configurations in this case is bn .

Part (b): Following the hint, since we have a total of n distinguishable balls and b bins
we can imagine the requested problem as equivalent to that of counting the number of
configurations of n balls and b 1 sticks. The b 1 sticks represents the internal bin edges
and the linear ordering of the balls between sticks represents the ball ordering within the
bin. Now to count this number we note that we can order n + b 1 distinguishable objects
in (n + b 1)! ways, but since the b 1 sticks are indistinguishable we need to divide by the
number of unique orderings of b 1 objects giving a total count of
(n + b 1)!
.
(b 1)!

Part (c): If the balls in each bin are in fact identical in the same manner in which we
needed to divide (n + b 1)! by the number of unique orderings of distinguishable internal
sticks (b 1)! we need to divide the result above by the number of unique orderings of these
n balls or n!. This gives  
(n + b 1)! n+b1
= .
(b 1)!n! n

Part (d): We assume in this part that we have more bins than balls or b > n. If we assume
for the moment that the balls are not identical then we have b choices for the location of the
first ball, b 1 choices for the location of the second ball, b 2 choices for the location of
the third ball and so on down to b n + 1 choices for the n-th ball. This gives
b!
b(b 1)(b 2) (b n + 2)(b n + 1) = ,
(b n)!
Ways to place n unique balls. Since the balls are in fact identical this number over counts
the total possible by n!. So we have
 
b! b
= ,
(b n)!n! n
placements of identical balls where no more than one ball can go in any given bin.

Part (e): We assume in this part that we have more balls than bins or n > b. Consider all
of our n indistinguishable balls lined up in a row and note that our problem is equivalent
to that of counting the number of ways we can select b 1 spaces (which will represent
the b 1 internal bin boundaries) from all n 1 possible spaces in our linear ordering of the
balls. The number of ways to select b 1 things from a set of n 1 is given by
 
n1
,
b1
or the claimed number.
CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #1 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.

If you use pseudocode in your assignment, please either actually use psuedocode or
include a written explanation of your code. The TA does not want to parse through
C or JAVA code with no comments.

If you fax in your problem set, please make sure you write clearly and darkly. Some
problem sets were very difficult to read. Also, make sure that you leave enough margins
so that none of your work is cut off.

The version of the Master Theorem that was given in lecture is slightly different from
that in the book. We gave case 2 as

f (n) = (nlogb a logk n) = T (n) = (nlogb a logk+1 n) for k 0

On exams, using the Master Theorem is normally quicker than other methods. But,
remember that cases 1 and 3 only apply when f (n) is polynomially smaller or larger,
which is different from asymptotically smaller or larger.

1. [16 points] Ordering By Asymptotic Growth Rates


Throughout this problem, you do not need to give any formal proofs of why one function
is , , etc... of another function, but please explain any nontrivial conclusions.

(a) [10 points] Do problem 3-3(a) on page 58 of CLRS.


Rank the following functions by order of growth; that is, find an arrangement
g1 , g2, . . . , g30 of the functions satisfying g1 = (g2 ), g2 = (g3 ), . . . , g29 = (g30 ).
Partition your list into equivalence classes such that f (n) and g(n) are in the
same class if and only if f (n) = (g(n)).

lg(lg n) 2lg n ( 2)lg n

n2 n! (lg n)!
3 n 2 2n
(2) n 3
lg n lg(n!) 2 n1/ lg n
ln ln n lg n n 2n nlg lg n ln n 1
lg n lg n n lg n
2 (lgn) e 4 (n + 1)! lg n
n+1
lg (lg n) 2 2 lg n
n 2n n lg n 22
Problem Set #1 Solutions 2

Answer: Most of the ranking is fairly straightforward. Several identities are


helpful:
nlg lg n = (lg n)lg n
n2 = 4lg n
lg n
n = 2
2 2 lg n = n 2/ lg n
1 = n1/ lg n
lg (lg n) = lg n 1 for n > 1

In addition, asymptotic bounds for Stirlings formula are helpful in ranking the
expressions with factorials:
n! = (nn+1/2 en )
lg(n!) = (n lg n)
(lg n)! = ((lg n)lg n+1/2 e lg n )

Each term gives a different equivalence class, where the > symbol means .
n+1 n
22 > 22 > (n + 1)! > n! > en >

nlg lg n
n 2n > 2n > ( 32 )n > > (lg n)! >
(lg n)lg n

n2 n lg n n
n3 > > > > ( 2)lg n >
4lg n lg(n!) 2 lg n


2 lg n
2 > lg2 n > ln n > lg n > ln ln n >

lg (lg n) 1
n
lg(lg n)

2lg > > >
lg n n 1/ lg n

(b) [2 points] Do problem 3-3(b) on page 58 of CLRS.


Give an example of a single nonnegative function f (n) such that for all functions
gi (n) in part (a), f (n) is neither O(gi (n)) nor (gi (n)).
n+2
Answer: f (n) = (1 + sin n) 22 .
(c) [2 points] Give an example of a single nonnegative function f (n) such that for
all functions gi(n) in part (a), f (n) = o(gi (n)).
Answer: f (n) = 1/n.
(d) [2 points] Give an example of a single nonnegative function f (n) such that for
all functions gi(n) in part (a), f (n) = (gi(n)).
2n
Answer: f (n) = 22 .
Problem Set #1 Solutions 3

2. [16 points] Recurrences


Give asymptotic upper and lower bounds for T (n) in each of the following recurrences.
Make your bounds as tight as possible, and justify your answers. You may assume
T (n) is constant for sufficiently small n.

(a) [2 points] T (n) = T (9n/10) + n.


Answer: T (n) = (n). We have a = 1, b = 10/9, f (n) = n so nlogb a = n0 = 1.
Since f (n) = n = (n0+ ), case 3 of the Master Theorem applies if we can show
the regularity condition holds. For all n, af (n/b) = 9n
10
9
10 9
n = cf (n) for c = 10 .
Therefore, case 3 tells us that T (n) = (n).

(b) [2 points] T (n) = T ( n) + 1.
Answer: T (n) = (lg lg n). We solve this problem by change of variables. Let
m = lg n, and S(m) = T (2m ). Then
T (n) = T (n1/2 ) + 1
T (2m ) = T (2m/2 ) + 1
S(m) = S(m/2) + 1
We have a = 1, b = 2, f (m) = 1 so mlogb a = m0 = 1. Since f (m) = (1), case 2
of the Master Theorem applies and we have S(m) = (lg m). To change back to
T(n), we have
T (n) = T (2m ) = S(m) = (lg m) = (lg lg n).

Alternatively, we could solve this problem by algebraic substitution.


T (n) = T (n1/2 ) + 1
= (T (n1/4 ) + 1) + 1
...
k
= T (n1/2 ) + k
k
When n1/2 2, we have that k lg lg n. Then, T (n) = (1) + lg lg n =
(lg lg n).
(c) [2 points] T (n) = 4T (n/2) + n2 lg n.
Answer: T (n) = (n2 lg2 n). We have a = 4, b = 2, f (n) = n2 lg n so nlogb a =
n2 . Since f (n) = (n2 lg n), case 2 of the Master Theorem applies and T (n) =
(n2 lg2 n).
(d) [2 points] T (n) = 5T (n/5) + n/ lg n.
Answer: T (n) = (n lg lg n). We have a = 5, b = 5, f (n) = n/ lg n so nlogb a = n.
None of the Master Theorem cases may be applied here, since f (n) is neither
polynomially bigger or smaller than n, and is not equal to (n lgk n) for any
k 0. Therefore, we will solve this problem by algebraic substitution.
T (n) = 5T (n/5) + n/ lg n
= 5(5T (n/25) + (n/5)/(lg(n/5))) + n/ lg n
Problem Set #1 Solutions 4

= 25T (n/25) + n/ lg(n/5) + n/ lg(n)


...
i1
5i T (n/5i) + n/ lg(n/5j ).
X
=
j=1

When i = log5 n the first term reduces to 5log5 n T (1), so we have


lg5 n1
(n/(lg(n/5j1 )))
X
T (n) = n(1) +
j=1
lg5 n1
X
= (n) + n (1/(lg n (j 1) lg2 5))
j=1
log5 n1
X
= (n) + n(1/ log2 5) (1/(log5 n (j 1)))
j=1
log5 n
X
= (n) + n log5 2 (1/i).
i=2

This is the harmonic sum, so we have T (n) = (n) + c2 n ln(log5 n) + (1) =


(n lg lg n).
(e) [2 points] T (n) = T (n/2) + T (n/4) + T (n/8) + n.
Answer: T (n) = (n). We solve this problem by guess-and-check. The total
size on each level of the recurrance tree is less than n, so we guess that f (n) = n
will dominate. Assume for all i < n that c1 n T (i) c2 n. Then,
c1 n/2 + c1 n/4 + c1 n/8 + kn T (n) c2 n/2 + c2 n/4 + c2 n/8 + kn
c1 n(1/2 + 1/4 + 1/8 + k/c1 ) T (n) c2 n(1/2 + 1/4 + 1/8 + k/c2 )
c1 n(7/8 + k/c1 ) T (n) c2 n(7/8 + k/c2 )

If c1 8k and c2 8k, then c1 n T (n) c2 n. So, T (n) = (n).

In general, if you have multiple recursive calls, the sum of the arguments to those
calls is less than n (in this case n/2 + n/4 + n/8 < n), and f (n) is reasonably
large, a good guess is T (n) = (f (n)).
(f) [2 points] T (n) = T (n 1) + 1/n.
Answer: T (n) = (lg n). We solve this problem by algebraic substitution.
T (n) = T (n 1) + 1/n
= T (n 2) + 1/(n 1) + 1/n
...
n
X
= (1) + 1/i
i=1
= ln n + (1)
Problem Set #1 Solutions 5

(g) [2 points] T (n) = T (n 1) + lg n.


Answer: T (n) = (n lg n). We solve this problem by algebraic substitution.
T (n) = T (n 1) + lg n
= T (n 2) + lg(n 1) + lg n
...
n
X
= (1) + lg i
i=1
n
Y
= (1) + lg( i)
i=1
= (1) + lg(n!)
= (n lg n)


(h) [2 points] T (n) = nT ( n) + n.
Answer: T (n) = (n lg lg n). We solve this problem by algebraic substitution.

T (n) = nT ( n) + n
= n1/2 (n1/4 T (n1/4 ) + n1/2 ) + n
= n3/4 T (n1/4 ) + 2n
= n3/4 (n1/8 T (n1/8 ) + n1/4 ) + 2n
= n7/8 T (n1/8 ) + 3n
...
k k
= n11/2 T (n1/2 ) + kn

k
When, n1/2 falls under 2, we have k > lg lg n. We then have T (n) = n11/ lg n T (2)+
n lg lg n = (n lg lg n).

3. [10 points] Integer Multiplication


Let u and v be two n-bit numbers, where for simplicity n is a power of 2. The
traditional multiplication algorithm requires (n2 ) operations. A divide-and-conquer
based algorithm splits the numbers into two equal parts, computing the product as

uv = (a2n/2 + b)(c2n/2 + d) = ac2n + (ad + bc)2n/2 + bd

Here, a and c are the higher order bits, and b and d are the lower order bits of u and v
respectively. Multiplications are done recursively, except multiplication by a power of
2, which is a simple bitshift and takes (n) time for an n-bit number. Addition and
subtraction also take (n) time.

(a) [4 points] Write a recurrence for the running time of this algorithm as stated.
Solve the recurrence and determine the running time.
Problem Set #1 Solutions 6

Answer: T (n) = 4T (n/2) + (n) = (n2 ). We divide the problem into 4


subproblems (ac, ad, bc, bd) of size n/2 each. The dividing step takes constant
time, and the recombining step involves adding and shifting n-bit numbers and
therefore takes time (n). This gives the recurrence relation T (n) = 4T (n/2) +
(n). For this case, we have a = 4, b = 2, f (n) = n so nlogb a = n2 . f (n) =
O(nlogb a ) so case 1 of the Master Theorem applies. Therefore, T (n) = (n2 ).
(b) [6 points] You now notice that ad+bc can be computed as (a+b)(c+d)acbd.
Why is this advantageous? Write and solve a recurrence for the running time of
the modified algorithm.
Answer: T (n) = 3T (n/2) + (n) = (nlog2 3 ). If we write ad + bc as (a + b)(c +
d) ac bd, then we only need to compute three integer multiplications of size
n/2, namely ac, bd, and (a + c)(c + d). This is advantageous since we replace
one multiplication with additions and subtractions, which are less expensive op-
erations. The divide step will now take time (n), since we need to calculate
a + c and c + d, and the recombining step will still take (n). This leads to the
recurrence relation T (n) = 3T (n/2) + (n). We have a = 3, b = 2, and f (n) = n
so nlogb a n1.585 . f (n) = O(n1.585 ) so case 1 of the Master Theorem applies.
Therefore, T (n) = (nlg 3 ).

4. [20 points] Stable Sorting


Recall that a sorting algorithm is stable if numbers with the same value appear in
the output array in the same order as they do in the input array. For each sorting
algorithm below, decide whether it is stable or not stable. If the algorithm is stable,
give a formal proof of its stability (using loop invariants if necessary). If the algorithm
is unstable, suggest a way to modify the algorithm to make it stable. This modification
should not alter the fundamental idea of the algorithm or its running time! Explain
(informally) why your modifications make the algorithm stable.

(a) [6 points] Insertion Sort: pseudocode given on page 17 of CLRS.


INSERTION-SORT(A)
1 for j 2 to length[A]
2 do key A[j]
3 . Insert A[j] into the sorted sequence A[1 . . . j 1]
4 ij1
5 while i > 0 and A[i] > key
6 do A[i + 1] A[i]
7 i i1
8 A[i + 1] key

Answer: Insertion sort is stable. We will prove this using the following loop
invariant: At the start of each interation of the for loop of lines 1-8, if A[a] =
A[b], a < b j 1 and distinct, then A[a] appeared before A[b] in the initial
array.
Initialization: Before the first loop iteration, j = 2 so there are no distinct
Problem Set #1 Solutions 7

elements a < b j 1 = 1. So, the condition holds trivially.


Maintenance: Given that the property holds before any iteration, we need to
show that it holds at the end of the iteration. During each iteration, we insert
A[j] into the sorted sequence A[1 . . . j 1]. For all a < b j 1, the property
holds at the end of the loop since we simply shift elements in the subarray and
dont change their respective order. For all a < b = j, the property holds at the
end of the loop since we insert j after all elements whose value is equal to A[j].
This is because the condition for shifting elements to the right is A[i] > key (line
5), so all the elements whose value equals key are not shifted and A[j] is inserted
after them. Thus, since we have shown the property is true for all a < b j 1
and a < b = j, we have shown it true for all a < b j and so the property is true
at the end of the loop.
Termination: When the for loop ends, j = n + 1, and the loop invariant states
that for all A[a] = A[b], a < b n, implies A[a] appeared before A[b] in the initial
array. This is the definition of stability and since it applies to the entire array A,
insertion sort is stable.
(b) [6 points] Mergesort: pseudocode given on pages 29 and 32 of CLRS.
MERGE(A, p, q, r)
1 n1 q p + 1
2 n2 r q
3 create arrays L[1 . . . n1 + 1] and R[1 . . . n2 + 1]
4 for i 1 to n1
5 do L[i] A[p + i 1]
6 for j 1 to n2
7 do R[j] A[q + j]
8 L[n1 + 1]
9 R[n2 + 1]
10 i1
11 j1
12 for k p to r
13 do if L[i] R[j]
14 then A[k] L[i]
15 i i+1
16 else A[k] R[j]
17 j j+1
MERGE-SORT(A, p, r)
1 if p < r
2 then q b(p + r)/2c
3 MERGE-SORT(A, p, q)
4 MERGE-SORT(A, q + 1, r)
5 MERGE(A, p, q, r)

Answer: Mergesort is stable. We prove this by induction on the fact that Merge-
sort is stable.
Problem Set #1 Solutions 8

Base Case: When we call merge-sort with indices p and r such that p 6< r (there-
fore p == r), we return the same array. So, calling mergesort on an array of size
one returns the same array, which is stable.
Induction: We assume that calling merge-sort on an array of size less than n
returns a stably sorted array. We then show that if we call merge-sort on an array
of size n, we also return a stably sorted array. Each call to mergesort contains two
calls to mergesort on smaller arrays. In addition, it merges these two subarrays
and returns. Since we assume that the calls to mergesort on smaller arrays return
stably sorted arrays, we need to show that the merge step on two stably sorted
arrays returns a stable array. If A[i] = A[j], i < j in the initial array, we need
f (i) < f (j) in the new array, where f is the function which gives the new positions
in the sorted array. If i and j are in the same half of the recursive merge-sort
call, then by assumption, they are in order when the call returns and they will
be in order in the merged array (since we take elements in order from each sorted
subarray). If i and j are in different subarrays, then we know that i is in the left
subarray and j is in the right subarray since i < j. In the merge step, we take
the elements from the left subarray while the left subarry element is less than or
equal to the right subarray element (line 13). Therefore, we will take element i
before taking element j and f (i) < f (j), the claim we are trying to prove.
Therefore, Mergesort is stable.
(c) [8 points] Quicksort: pseudocode given on page 146 of CLRS.
QUICKSORT(A, p, r)
1 if p < r
2 then q PARTITION(A, p, r)
3 QUICKSORT(A, p, q 1)
4 QUICKSORT(A, q + 1, r)

PARTITION(A, p, r)
1 x A[r]
2 i p1
3 for j p to r 1
4 do if A[j] x
5 then i i + 1
6 exchange A[i] A[j]
7 exchange A[i + 1] A[r]
8 return i + 1

Answer: Quicksort is not stable. To make it stable, we can add a new field to
each array element, which indicates the index of that element in the original array.
Then, when we sort, we can sort on the condition (line 4) A[j] < x OR (A[j] == x
AND index(A[j]) < index(x)). At the end of the sort, we are guaranteed to have
all the elements in sorted order, and for any i < j, such that A[i] equals A[j], we
will have index(A[i]) < index(A[j]) so the sort will be stable.
Problem Set #1 Solutions 9

5. [22 points] Computing Fibonacci Numbers


Recall the Fibonacci numbers as defined in lecture and on page 56 of CLRS. Through-
out this problem assume that the cost of integer addition, subtraction, multiplication,
as well as reading from memory or writing to memory is (1), independent of the
actual size of the numbers. We will compare the efficiency of different algorithms for
computing Fn , the nth Fibonacci number.

(a) [5 points] First, consider a naive recursive algorithm:

int Fib (int n) {


// recursion
if (n >= 2) return Fib(n-1) + Fib(n-2);

// base cases
if (n == 1) return 1;
if (n == 0) return 0;

// error if none of the above returns


}

Sketch a recursion tree for this algorithm. During the computation of Fib(n), how
many times is Fib(n-1) called? Fib(n-2)? Fib(n-3)? Fib(2)? Use formula (3.23)
on page 56 of CLRS to conclude that this algorithm takes time exponential in n.

i i 1+ 5 1 5
Fi = , where = and = (1)
5 2 2
Answer:

F(n)

F(n1) F(n2)

F(n2) F(n3) F(n3) F(n4)

F(n3) F(n4) F(n4) F(n5) F(n4) F(n5) F(n5) F(n6)

We call F ib(n 1) one time during the recursion, F ib(n 2) 2 times, F ib(n 3)
3 times, F ib(n 4) 5 times, . . ., F ib(2) Fn1 times. Each node in the recurrence
Problem Set #1 Solutions 10

tree takes constant time to evaluate, so we need to calculate the number of nodes
in the tree. T (n) = ( ni=1 Fi ). Using formula 3.23 in the book, we get
P

n
X i i
T (n) = ( )
i=1 5
As n grows large, the i term goes to zero, so we are left with
n
i
) = (n )
X
T (n) = (
i=1 5
So, the algorithm takes time exponential in n.
(b) [5 points] Notice that our recursion tree grows exponentially because the same
computation is done many times over. We now modify the naive algorithm to only
compute each Fib(i) once, and store the result in an array. If we ever need Fib(i)
again, we simply reuse the value rather than recomputing it. This technique is
called memoization and we will revisit it when we cover dynamic programming
later in the course.
Prune your recursion tree from part (a) to reflect this modification. Considering
the amount of computation done at each node is (1), what is the total amount
of computation involved in finding Fib(n)?
Answer:

Fib(n)

Fib(n1) Fib(n2)

Fib(n2) Fib(n3)

Fib(n3) Fib(n4)

... Fib(n5)

As in part (a), the time to calculate the nth Fibonacci number Fn is equal to the
time to calculate Fn1 , plus the time to calculate Fn2 , plus the time to add Fn1
to Fn2 . However, because of memoization, the time to calculate Fn2 is constant
once Fn1 has already been calculated. Therefore, the recurrence for this modified
algorithm is T (n) = T (n 1) + (1). It is easy to use the algebraic substitution
method to verify that the solution to this recurrence is T (n) = (n).
Problem Set #1 Solutions 11

(c) [4 points] Prove that


!n !
1 1 Fn+1 Fn
=
1 0 Fn Fn1

for n = 1, 2, 3, . . . .
Hint: The last line of the question should immediately suggest what proof tech-
nique would be useful here.
Answer: We prove the statement by mathematical induction. For the base case
of n = 1, we get
!1 !
1 1 F2 F1
= (2)
1 0 F1 F0
which certainly holds. Now, we assume the statement holds for n 1. Then,
!n !n1 !
1 1 1 1 1 1
=
1 0 1 0 1 0
! !
Fn Fn1 1 1
=
Fn1 Fn2 1 0
!
Fn + Fn1 Fn
=
Fn1 + Fn2 Fn1
!
Fn+1 Fn
=
Fn Fn1

Thus, we have shown that the statement holds for all n.


(d) [8 points] Use part (c) or formula (3.23) to design a simple divide-and-conquer
algorithm that computes the nth Fibonacci number Fn in time (lg n).
!
1 1
Answer: Let A be the matrix of part (c). To compute the nth Fi-
1 0
bonacci number Fn , we can simply exponentiate the matrix A to the nth power
and take the element An2,1 . An efficient divide-and-conquer algorithm for this
problem uses the notion of repeated squaring. In other words, to calculate An ,
observe that
(
n (An/2 )2 if n is even
A =
(Abn/2c )2 A if n is odd
This algorithm satisfies the recurrence T (n) = T (n/2) + (1) because we consider
multiplying two 2 2 matrices as a constant time operation and because we have
reduced a problem of size n to one of size bn/2c. We can solve this recurrence
using the master theorem case 2, and arrive at a solution of T (n) = (lg n).

6. [26 points] Algorithm Design


Problem Set #1 Solutions 12

(a) [10 points] Design a (n lg n)-time algorithm that, given an array A of n integers
and another integer x, determines whether or not there exist two (not necessarily
distinct) elements in A whose sum is exactly x. This is problem 2.3-7 on page 37
of CLRS, slightly reworded for the sake of clarity.
Answer: We first sort the elements in the array using a sorting algorithm such
as merge-sort which runs in time (n lg n). Then, we can find if two elements
exist in A whose sum is x as follows. For each element A[i] in A, set y = A[i] x.
Using binary search, find if the element y exists in A. If so, return A[i] and y.
If we cant find y for any A[i], then return that no such pair of elements exists.
Each binary search takes time (lg n), and there are n of them. So, the total
time for this procedure is T (n) = (n lg n) + (n lg n) where the first term comes
from sorting and the second term comes from performing binary search for each
of the n elements. Therefore, the total running time is T (n) = (n lg n).
An alternate procedure to find the two elements in the sorted array is given below:
SUM-TO-X(A)
1 Merge-Sort(A)
2 i1
3 j length(A)
4 while i j
5 if A[i] + A[j] equals x
6 return A[i], A[j]
7 if A[i] + A[j] < x
8 then i i + 1
9 if A[i] + A[j] > x
10 then j j 1
We set counters at the two ends of the array. If their sum is x, we return those
values. If the sum is less than x, we need a bigger sum so we increment the bottom
counter. If the sum is greater than x, we decrement the top counter. The loop
does (n) iterations, since at each iteration we either increment i or decrement j
so j i is always decreasing and we terminate when j i < 0. However, this still
runs in time (n lg n) since the running time is dominated by sorting.
(b) [16 points] The majority element of an array A of length n is the element that
appears strictly more than bn/2c times in the array. Note that if such an
element exists, it must be unique.
Design a (n)-time algorithm that, given an array A of n objects, finds the
majority element or reports that no such element exists. Assume that two objects
can be compared for equality, read, written and copied in (1) time, but no other
operations are allowed (for instance, there is no < operator). Explain why
your algorithm is correct (no formal proof necessary).
Hint: It is possible to find a candidate solution using only one pass through the
array, with the help of an auxiliary data structure such as a stack or a queue.
Then with one more pass you can determine whether this candidate is indeed the
majority element.
Answer: We will give an algorithm to solve this problem which uses an auxiliary
Problem Set #1 Solutions 13

stack and a proof of why it is correct. The following is the pseudocode for the
algorithm.
FIND-MAJORITY-ELEMENT(A)
1 for i 1 to length[A]
2 if stack is empty
3 then push A[i] on the stack
4 else if A[i] equals top element on the stack
5 then push A[i] on the stack
6 else pop the stack
7 if stack is empty
8 then return NoMajority
9 candidate top element on the stack
10 counter 0
11 for i 1 to length[A]
12 if A[i] equals candidate
13 then counter counter + 1
14 if counter > blength[A]/2c
15 then return candidate
16 return NoMajority
The procedure first generates a candidate object from the array. It finds this
element using the stack by looping over the array. If the stack is empty or the
current element is the same as the top object on the stack, the element is pushed
onto the stack. If the top object of the stack is different from the current element,
we pop that object off the stack.
Claim: If a majority element exists, it will be on the stack at the end of this part
of the procedure.
Proof: (by contradiction) Call the majority element x and say it appears i >
bn/2c times. Each time x is encountered, it is either pushed on the stack or an
element (different from x) is popped off the stack. There are n i < i elements
different from x. Assume x is not on the stack at the end of the procedure. Then,
each of the i elements of x must have either popped another element off the stack,
or been popped off by another element. However, there are only n i < i other
elements, so this is a contradiction. Therefore, x must be on the stack at the end
of the procedure.
Notice that this proof does not show that if an element is on the stack at the end
of the procedure that it is the majority element. We can construct simple coun-
terexamples (A = [1, 2, 3]) where this is not the case. Therefore, after obtaining
our candidate majority element solution, we check whether it is indeed the major-
ity element (lines 9-16). We do this by scanning through the array and counting
the number of times the element candidate appears. We return candidate if it
appears more than bn/2c times, else we report that no majority element exists.
This procedure scans through the array twice and does a constant amount of
computation (pushing and popping elements on the stack take constant time) at
each step. Therefore the running time is T (n) = cn = (n).
CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #2 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.

Remember you can only split an expectation of a product into the product of the
expectations if the two terms are independent. Many students did this on question
3c either without justification or justifying it as linearity of expectation, which is
incorrect.

For the skip list question 4b, many students found the expected number of nodes
between lef t[i + 1].below and right[i + 1].below by saying the expected number of
nodes at level i + 1 is npi+1 and the expected number of nodes at level i is npi . Then,
if you divide the number of nodes at i by the number at i + 1, you get an average
interval of 1/p. While this gives the correct answer, it is not a valid argument as it
stands. For example, lets say you always propagate the first nodes in level i - you will
get an interval of length 1 with probability 1/p and an interval of length npi (1 p)
with probability 1 1/p, which clearly gives you a different expectation. You need to
use properties other than just the expected number of nodes to calculate the expected
interval length.

1. [18 points] Probability and Conditional Probability


Throughout this problem, please justify your answers mathematically as well as
logically; however, you do not have to give any formal proofs.

(a) [5 points] Do problem C.2-9 on page 1106 of CLRS. Assume that initially, the
prize is placed behind one of the three curtains randomly.
Answer: The answer is not 1/2, because now the two curtains are no longer
equally likely to hide the prize. In fact, the original 3 cases are still equally likely,
but now in two of the cases the prize is behind the curtain that is not revealed or
chosen. Therefore, the probability of winning if you stay is 1/3, if you switch is
2/3.
(b) [5 points] Do problem C.2-10 on page 1106 of CLRS.
Answer: This is essentially the same problem, except now there is no option
to switch. The prisoners are the curtains, freedom is the prize, and the guards
revelation is equivalent to the emcees revelation in the previous question. Thus,
the probability that X will go free is 1/3.
Problem Set #2 Solutions 2

(c) [8 points] Consider the following game using a standard 52-card deck (with 26
red cards and 26 black cards):
i. the deck D is shuffled randomly.
ii. one at a time, the top card of D is removed and revealed until you say stop
or only one card remains.
iii. if the next card is red, you win the game. if the next card is black, you lose
the game.
Consider the following algorithmic strategy for playing this game:
i. count the number of black cards (b) and red cards (r) revealed thus far.
ii. as soon as b > r, say stop.
What is the probability of success for this strategy? Is there a better strategy?
Can you prove a useful upper bound on the probability of success for any legal
strategy?
Hint: Consider the following modification to the game: after you say stop,
rather than looking at the top card of D, we look at the bottom card.
Answer: For any given strategy S, let P rS {(b, r)} be the probability that we
stop after we have seen b black cards and r red cards. Note that some of these
may be 0, for example, using the strategy in question we will only stop when
b = r + 1 or (b, r) = (25, 26).
Since we assume all permutations of the deck to be equally likely, the remaining
52 b r cards are in random order, so the probability of success (top remaining
card is red) is just
26 r
P rS {success | (b, r)} = .
52 b r
Thus, we can write
X 26 r
P rS {success} = P rS {(b, r)} .
52 b r
(b,r)

Now notice that (26 r)/(52 b r) is also the probability that the bottom card
is red given that we stop at (b, r). Thus, we can say
X
P rS {success} = P rS {(b, r)} P r{bottom = red | (b, r)}.
(b,r)

Now we manipulate the sum by multiplying the two probabilities:


X
P rS {success} = P r{bottom = red (b, r)} = P r{bottom = red} = 1/2.
(b,r)

The argument applies for any legal strategy, thus, regardless of the strategy, we
succeed with probability 1/2.
If you are uncomfortable with some of the probabilistic manipulation and
reasoning in this solution, please review Appendix C in CLRS, particularly section
C.2 and Bayess theorem.
Problem Set #2 Solutions 3

2. [12 points] Modifying Quicksort


Consider the following modification tothe deterministic quicksort algorithm: instead
of using A[n] as pivot, take the last 2 n + 1 elements of A, sort them using insertion
sort, then use themiddle element of these as the pivot. Assume that this guarantees
there are at least n elements in each subarray after partitioning - we will ignore the
issue of repeated elements in this problem. As usual, ignore the issue of rounding as
well.

(a) [3 points] Write a recurrence for the worst-case running time T (n) of this
algorithm.

Answer: Our partition guarantees that there are at least n elements in each
subarray. In the worst case, all the remaining elements will go to one subarray.
Then, we will need to solve one subproblem
of the size n and one of the size
n n. Also, we need to sort the 2 n + 1 elements to find the pivot. Using
insertion sort, this is a worst case running time of ((2 n + 1)2 ) = (n). Then,
we find the median of the sorted sample, a (1) step. In addition, we need to
partition the elements at each step, a(n) operation.
So in the worst-case, the
recurrence relation will be T (n) = T ( n) + T (n n) + (n).
(b) [2 points] Draw the recursion tree for the expression you came up with in part
(a). Label the work in the top 3 levels of the tree.
Answer:

=n
n

1/2 1/2
n nn =n

1/4 1/2 1/4 1/2 1/2 1/2 1/2 1/2


n n n (nn ) nn (nn ) =n

(c) [6 points] How many levels does it take before the shortest branch reaches a
leaf? the longest branch (an asymptotic upper bound is sufficient)?
Hint: Consider writing a recurrence
p for
the height of the longest branch. You
may find the approximation n n n 1/2 helpful in guessing a solution
for this recurrence.

Answer: The shortest branch is the one where everytime we call T ( n). At each
i
level i, we will call T (n1/2 ). We assume T (n) is a constant for small values of n,
i
so we find the value of i for which n1/2 2. This is true for i lg lg n. Thus,
Problem Set #2 Solutions 4

the shortest branch reaches a leaf in lg lg n steps.


The longest branch is the one where everytime we call T (n n). At the second
p
level we will call T (n n n n) T (n n n1/2). So, at this level,
we essentially subtract
another n. Therefore, we can guess that at each level i,
we call T (n i n) which will be a constant when i = n. We can now check to
see that this is in fact an upper bound for the number of levels. Define h(n)
to be
the number of levels in the recurrence tree. We know that h(n) = h(n n) + 1,
since we add one level each time we recurse. We guess that h(i) c i for i < n
and check.


h(n) = h(n n) + 1

q
c n n+1

c( n 1/2) + 1

= c n c/2 + 1

c n


which is true for c 2. Therefore, we know that the longest branch is O( n).
(d) [1 point] Using your answers from parts (b) and (c), give a big-O bound on T (n).
Answer: T (n) = O(n3/2 ). Looking at the recurrence tree from part (b), we see
that we do (n) work on each level. We showed
in part (c) that the longest branch
of the recurrence tree had a height of O( n) levels. So, we know the recurrence
is bounded by T (n) = O(n3/2 ).

3. [15 points] Alternative Quicksort Analysis


In this problem, you will analyze the running time of the randomized quicksort
algorithm using a different approach than in lecture. Instead of counting the expected
number of comparisons, this approach focuses on the expected running time of each
recursive call to randomized quicksort.
Throughout your analysis, please be as formal as possible.

(a) [2 points] Do problem 7-2(a) on page 160 of CLRS.


Answer: We know that we select pivots from the array uniformly at random.
Since there are n elements in the array, and since the sum of the probabilities
of choosing any one element as the pivot must equal one, each element must be
chosen with probability 1/n. If we define the indicator random Pvariable Xi = I{ith
smallest element chosen as the pivot}, then E[Xi ] is simply nj=1 P r{select j j
is the ith smallest element}.
Pn These are independent, so we can break apart
th
the product and get j=1 P r{select j} P r{j is the i smallest element} =
Pn th
j=1 (1/n) (1/n), since each element is equally likely to be the i smallest
element. This gives E[Xi ] = 1/n.
Problem Set #2 Solutions 5

(b) [3 points] Do problem 7-2(b) on page 161 of CLRS.


Answer: The expected running time of quicksort depends on the sizes of the
subarrays after partitioning. We can sum over the sizes resulting from all possible
pivots multiplied by the probability of that pivot. If the pivot is at q, then the
resulting subarrays will have size q 1 and n q. In addition, it takes (n) time
to do the partitioning. So, the total expected running time is:
E[T (n)] = E[ nq=1 Xq (T (q 1) + T (n q) + (n))]
P

(c) [2 points] Do problem 7-2(c) on page 161 of CLRS.


Answer: By linearity of expectation, we can move the summation outside of the
expectation.
n
X
E[T (n)] = E[Xq (T (q 1) + T (n q) + (n))]
q=1

Because Xq is independent from the time is takes to do the recursive calls, we can
split the expectation of the product into the product of expectations.
n
X
E[T (n)] = E[Xq ] E[T (q 1) + T (n q) + (n)]
q=1

Substituting in the value for E[Xq ] that we solved in part (a) and again changing
the expectation of the sum into a sum of expectations, we have

n
X 1
E[T (n)] = (E[T (q 1)] + E[T (n q)] + E[(n)])
q=1
n
n
1X
= (E[T (q 1)] + E[T (n q)] + (n))
n q=1
n n n
1 X X X
= ( E[T (q 1)] + E[T (n q)] + (n))
n q=1 q=1 q=1
1
= ((E[T (0)] + E[T (1)] + + E[T (n 1)]) +
n
(E[T (n 1)] + E[T (n 2)] + + E[T (0)]) + n(n))
n1
1 X
= (2 E[T (q)]) + (n)
n q=2

since we consider E[T (0)] and E[T (1)] to be (1).


(d) [6 points] Do problem 7-2(d) on page 161 of CLRS.
Problem Set #2 Solutions 6

Answer:
n1 dn/2e1 n1
X X X
k lg k = k lg k + k lg k
k=2 k=2 k=dn/2e
dn/2e1 n1
X X
k lg(n/2) + k lg n
k=2 k=dn/2e
dn/2e1 n1
X X
= lg(n/2) k + lg n k
k=2 k=dn/2e
   
(n/2 1)(n/2) (n 1)(n) (n/2 1)(n/2)
= lg(n/2) 1 + lg(n)
2 2 2
2
 2 2

(n/2) n (n/2)
(lg n lg 2) + (lg n)
2 2 2
2 2 2 2
n n n n
= (lg n) + (lg n) (lg n)
8 8 2 8
1 2 1 2
= n lg n n
2 8

(e) [2 points] Do problem 7-2(e) on page 161 of CLRS. Note that you are actually
showing E[T (n)] = O(n lg n), but the bound is trivial.
Answer: We will show this using the guess-and-check method. First, we guess
that E[T (q)] cq lg q for 2 q < n. Then, we show that the same is true for
E[T (n)].
n1
2X
E[T (n)] = E[T (q)] + kn
n q=2
n1
2X
cq lg q + kn
n q=2
 
2 1 2 1 2
c n lg n n + kn
n 2 8
 
1 1
= 2c n lg n n + kn
2 8
1
= cn lg n cn + kn
4
cn lg n
for c 4k.
4. [19 points] Skip List Analysis
In this problem, you will analyze the behavior of the skip list data structure introduced
in lecture. Please see the Skip List Summary handout for more information, including
detailed descriptions of the FIND, INSERT, and DELETE operations.
Problem Set #2 Solutions 7

Throughout this problem, we will consider a skip list with L levels and n elements, in
which elements are propagated to the next level with probability p, 0 < p < 1.

(a) [5 points] What is the expected value of L in terms of n and p? For simplicity
of analysis, consider levels that you expect to contain less than 1 cell to be
nonexistent. In practice, how might you enforce this assumption?
Answer: E[L] = (log1/p n). We can define the indicator variable Ii,k to be
equal to 1 if and only if the element A[i] is present in the k th level of the skip list.
Then,
Xn
E[L] = min(E[ Ij,k ] 1)
k
j=1

the expected number of levels in the skip list is equal to the minimum level where
the expected number of elements in the list is 1. By linearity of expectation,
we can move the summation outside of the expectation:
n
X
E[L] = min( E[Ij,k ] 1)
k
j=1

The expectation of an indicator variable is simply the probability of that event.


What is the probability that element A[i] is present in the k th level of the skip
list? It is the probability that we propagated A[i] up from level 0 to the level
k. This is the product of k independent propagation events, each of which has
probability p. Thus, the equation for the expected number of levels is

n
X
E[L] = min( pk 1)
k
j=1
n
X
k
= min(p 1 1)
k
j=1

= min(npk 1)
k

The value npk falls below 1 when k log1/p n. So, we expect to have E[L] =
(log1/p n).
(b) [8 points] Consider the work done by the SEARCH operation at level i, where
i < L. We must examine, in the worst case, all cells between lef t[i + 1].below and
right[i + 1].below (since lef t[L] and right[L] are not actually defined, we can say
that in level L 1 we look between dummy and NULL). Thus, we examine all
cells immediately after some given cell in level i that have not been propagated
to level i + 1. What is the expected number of such cells? What is the expected
running time of the SEARCH operation in terms of n and p?
Problem Set #2 Solutions 8

Answer: We are trying to find the expected number of elements examined on


level i, which is equal to the number of elements between lef t[i + 1].below and
right[i + 1].below. This is equal to the expected number of elements in level i
between two elements which are propagated up to level i + 1. Since we know
at least one element is propagated (the dummy element is always propagated),
we simply compute the expected number of elements until another element is
propagated. Since each element is propagated independently with probability
p, the probability that the kth next element is the first Pto be propagated is
k1 k1
(1 p) p. Therefore, the expected value of k is E[k] = k=1 kp(1 p) . This
is the expectation of the geometric distribution, so the expectation is given by
E[k] = 1/p (p. 1112 CLRS). So, we expect to have to search through 1/p elements
at each of the i levels. Since we found in part (a) that there are (log1/p n) levels,
we expect SEARCH to take time ((1/p) log1/p n) = ((1/p) log1/p n).
(c) [3 points] Use your answers to the previous parts to find the expected running
time of the INSERT and DELETE operations.
Answer: INSERT and DELETE first call SEARCH, which runs in expected time
((1/p)lg1/p n). Inserting and deleting an element from each level of the skip list
takes (1) time.
P Thek1 expected number of levels that each element is propagated is
E[levels] = k=1 kp (1p) = 1/(1p), since this is once again the expectation
of a geometric distribution. So, the total expected running time for INSERT and
DELETE is ((1/p) lg1/p n) + (1/(1 p))(1) = ((1/p) lg1/p n + 1/(1 p)).
Notice that the maximum number of levels is log1/p n, so the first term dominates
the second term.
(d) [3 points] Asymptotically, in terms of n and p, what is the expected amount of
memory used by the skip list data structure?
Answer: Each cell in the skip list takes a constant amount of memory since we
need to store the four fields next, above, below, and key. The expected number
of cells in the skip list is the sum over all elements A[j] of the number of levels
that A[j] appears in.
n
X
E[num cells] = E[ (num levels that A[j] appears in)]
j=1

By linearity of expectation, we can pull the summation outside of the expectation.


n
X
E[num cells] = E[num levels that A[j] appears in]
j=1

We found the expected number of levels in part (c), names E[levels] = 1/(1 p).
So,
n
X
E[num cells] = 1/(1 p) = n/(1 p).
j=1

So, the expected amount of memory is (n/(1 p)).


Problem Set #2 Solutions 9

5. [18 points] Weighted Selection


Consider some ways to generalize the notion of the median and the ith element.
(a) [1 point] Do problem 9-2(a) on page 194 of CLRS.
P
Answer: We have that the weighted median xk satisfies the formulas xi <xk wi <
1
wi 21 . For wi = 1/n for i = 1, 2, . . . , n, these formulas reduce to
P
2
P and xi >xkP
xi <xk wi = Pxi <xk 1/n = y/n < 1/2 where y is the number of elements smaller
than xk and xi >xk 1/n = (n y 1)/n 1/2 where n y 1 is the number
of elements greater than to xk . This shows that y < n/2 and y n/2 1. This
states that exactly n/2 1 elements are smaller than xk for even n and exactly
bn/2c elements are smaller than xk for odd n. These is precisely the definition
for the lower median.
(b) [2 points] Do problem 9-2(b) on page 194 of CLRS.
Answer: One can calculate the weighted median in (n lg n) worst case time
using sorting. First, one sorts the array using merge sort which has worst-case
running time (n lg n). Then we iterate through the array, computing k1
P
i=1 wi ,
the total weight of the first k 1 elements in the array. We find the last element
Pk1
k 1 for which i=1 wi < 1/2. Then element k satisfies the first equation. It
also satisfies the second equation, since ni=k+1 wi = 1 ki=1 wi 1/2 since we
P P
know that k 1 was the last element for which the sum was less than 1/2, so the
sum up to k must be 1/2. Therefore, k is the weighted median, and we have
found it in (n) time after sorting, so the total amount of time is (n lg n).
(c) [10 points] Do problem 9-2(c) on page 194 of CLRS.
Answer: The main idea is to use deterministic SELECT to compute the regular
median in (n) worst-case time. We can then use this median to partition our
array into two (almost) equal halves, and look for the weighted median in either
one or the other half. The recurrence will be T (n) = T (n/2) + (n), which yields
T (n) = (n). In giving the pseudocode we will ignore floors and ceilings for
clarity, thus, for instance, the median has index n/2.
W-SELECT takes 4 parameters - the array A, lef t and right P boundaries, and
weight
P w. We look for an element xm that will satisfy xi <xm wi < w and
w
xi >xm i 1 w.

W-SELECT(A, lef t, right, w)


i. Call SELECT (the deterministic version) to find the median m of A.
ii. Partition A around m.
iii. Compute the total weight W of all the elements in the lower partition.
iv. If W < w but W + wn/2 w, return m.
v. Else if W < w, recursively call W-SELECT(A, n/2, n, w W wn/2 ).
vi. Else (if W > w), recursively call W-SELECT(A, 1, n/2, w).
This is a little more general than necessary for weighted median, but it helps in
the next part of the problem. To compute the weighted median of an array A, we
call W-SELECT(A, 1, n, 1/2).
Problem Set #2 Solutions 10

(d) [5 points] Consider the following generalization of the ith element: the weighted
ith element is the element xk satisfying
X i X ni
wj < and wj
xj <xk
n x >x
n
j k

Modify your algorithms from parts (b) and (c) to compute the weighted ith
element in, respectively, (n lg n) and (n) worst-cased running time.
Answer:
Pk1 We can modify the algorithm in part (b) by simply comparing our sum
i=1 w i to i/n instead of 1/2. The rest of the analysis holds as before. The
running time is still dominated by the sort which takes (n lg n). The actual
selection of the weighted ith element from the sorted array takes time (n) since
it consists of one pass through the sorted array, summing the weights.
In part (c), we can simply call W-SELECT(A, 1, n, i/n).

6. [28 points] Prisoners Other Dilemma


An evil computer science professor has kidnapped n of his students and locked them up
in a dungeon. Each is kept in a separate cell in complete isolation from others, except
that each evening one student is chosen randomly to spend the night in a conference
room. The conference room is empty except it contains a switch, which may be toggled
ON or OFF. The only way to observe or change the state of the switch is to spend a
night in the conference room. Initially, the switch is known to be in the OFF position.
The students are told that once they have all been in the room at least once, one of
them needs to tell this to the professor (this can be done when he is transferring the
student to the conference room in the evening or back to the cell in the morning). If
the claim is true, all students are set free and receive their degrees. If the claim is
false, the students will be imprisoned forever and forced to proofread problem sets and
papers for food.
The students are given one hour to come up with a joint strategy, after which point
they will be taken to their cells and will only be able to communicate by observing
and toggling the switch. Luckily, the students have studied algorithms and are able to
come up with a solution plan that guarantees that when they do make the claim, it
will be correct. Your job will be to analyze the expected time of their solution.

(a) [10 points] Consider the following idea: one of the students is designated as the
counter. His job will be to toggle the switch OFF anytime he enters the room
and sees that the switch is set to ON. Everyone else will toggle the switch ON if
its set to OFF, but only once.
Who can make the claim and when? Formally analyze the expected running time
of this algorithm. Your answer should be asymptotic in terms of n.
Answer: E[time] = (n2 ). The counter can make the claim that everyone has
been in the room once he has toggled the switch to OFF n 1 times. Since each
student besides the counter sets the switch to ON exactly once, we know that
n 1 distinct students besides the counter have been in the room. So, the counter
Problem Set #2 Solutions 11

knows that all n students have been in the room exactly once.
We can analyze the expected running time of this algorithm by breaking the
sequence of students in the room into periods. We will define two types of periods
Xi - the number of students who enter the room until (and including) the one
who sets the switch to ON for the ith time.
Yi - the number of students who enter the room after the ith student has turned
the switch ON until (and including) the counter who turns the switch to OFF.
For example, if student 1 is the counter and there are 4 students, then the following
sequence would be broken up into the given periods:
4123431224131
X1 = {4}, Y1 = {1}, X2 = {2}, Y2 = {3, 4, 3, 1}, X3 = {2, 2, 4, 1, 3}, Y3 = {1}
Notice that the periods run X1 , Y1 , X2 , Y2 , . . . , Xn1 , Yn1. After period Yn1 we
are finished because the counter has turned off the switch n 1 times.
Pn1
The expected length of time for the algorithm is E[time] = E[ i=1 (Xi + Yi )].
By linearity of
Pn1 expectation, we can pull the sum outside of the expectation.
E[time] = i=1 (E[Xi ] + E[Yi ]).

Xi is the number of students who enter the room until one can set the switch to
ON. After i 1 students have set the switch to ON, there are (n 1) (i 1)
students who can set it to ON. Since we choose students uniformly at random,
the probability at any point that one of these is selected is (n i)/n. Thus,
P r{Xi = k} = ( ni
n
)j1( ni ). This is the geomtric series, and its expectation is
n
given by E[Xi ] = ni .

Similarily, we can find the expected value of Yi , the number of students who
enter the room after the ith student turns on the switch until the counter enters.
The probability that the counter enters is 1/n. So, P r{Yi = k} = ( n1 n
)j1( n1 ).
Again, this is a geometric distribution with expected value E[Yi ] = n. Using these
formulas, we can find the expected length of time.
n1  
X n
E[time] = +n
i=1
n i
n1
X 1
= n(n 1) + n
i=1
ni
n1
X 1
= n(n 1) + n
j=1
j
= n(n 1) + n(ln(n 1))
= (n2 )

(b) [10 points] Now consider the following modification to this idea: instead of
deciding on the counter ahead of time, the counter will be the first student to
Problem Set #2 Solutions 12

enter the room twice. Now depending on what day that occurs, the counter will
know how many distinct people have been in the room already. Notice that this
means the students need different rules for the first n days of the imprisonment -
after that, they can continue using the algorithm from part (a).
How must the students behave during the first n days to make this work? Pay
particular attention to what happens on day n. Analyze the running time of
the modified algorithm - we do not expect a formal analysis this time, but your
explanation should be complete and mathematical.
Answer: For the first n days everyone should act as follows:
i. The switch remains OFF until someone has been in the room twice. That
person turns the switch ON and becomes the counter, setting the count to
j 2, where j is the day when he enters the room the second time.
ii. If someone other than the counter enters the room and finds the switch OFF,
the counter has not been determined yet. Thus, that person will be counted
in the j 2 and does not touch the switch after day n.
iii. If someone other than the counter enters the room and finds the switch
ON, the counter has been determined. Therefore, that person has not been
counted in j 2 and must participate in the algorithm after day n. Same
goes for anyone who has not entered the room at all during days 1 through
n.
iv. Finally, the person who is in the room on day n turns the switch OFF prior
to beginning the second phase. If the person entering the room on day n finds
the switch OFF, then nobody has been in the room twice and that person
can make the claim.
After the first n days, everyone should act as in part (a) with the counter
determined, except that the people who entered the room when the switch was
OFF (befor the counter was determined) no longer participate.
The expected running time of this algorithm depends on how many people we
counted during the first n days, call that number j. We will first analyze the
expected time after the first n days based on j. As in part (a), we alternate time
periods Xi , Yi , but now since j people have already been counted, we start with
period Xj+1. Therefore, the expected time is given below with the sum starting
from j + 1

n1  
X n
E[time|j] = +n
i=j+1
n i
n1
X 1
= n(n j 1) + n
i=j+1
ni
= n(n j 1) + n(ln(n j 1))

Now we will bound the probability of j, the number of people counted during the
Problem Set #2 Solutions 13

first n days. This is the birthday paradox problem, where the days are the people
in the birthday
paradox, and the people are the birthdays. We know that when
j = ( n), we have P r{someone enters twice in j days} 1/2. So, we can
now bound our expected time.

n1
X
E[time] = n + P r{j}E[time|j]
j=0

c n n1
X X
= n+ P r{j}E[time|j] + P r{j}E[time|j]

j=0 j=c n+1

c n
X
n+ P r{j}E[time|c n] + 0
j=0

c n
X
= n + n(n c n 1) + n(ln(n c n 1)) P r{j}
j=0

n + n(n c n 1) + n(ln n) (1/2)
n + (1/2)n2 (c/2)n3/2 n + (n ln n)
= (n2 )

This expected time is also O(n2 ), as its bounded above by n+E[time|0] = (n2 ).
Thus, our asymptotic expected time remains (n2 ).
(c) [8 points] It is possible to do asymptotically better than your answers in parts
(a) and (b). However, there are well-defined lower bounds on the performance of
any correct algorithm for this problem. For instance, since all students have to
have been in the room at the time the claim is made, clearly no correct algorithm
can have an expected running time asymptotically less than (n). Can you come
up with a tighter lower bound? Argue that your answer is correct; you may use
results proven in class or in the textbook.
Answer: No correct algorithm can have a better expected running time than
(n lg n). As we proved in class with the balls and bins question, the expected
amount of time until each bin has at least one ball is (n lg n). In this question,
the days are balls and the students are bins. We want the expected number time
until each students has been in the room for at least one day. So, the expected
number of days is (n lg n). Any algorithm the students come up with cant
have an expected running time faster than the expected time for the condition to
actually hold, otherwise it would not be correct. Therefore, the expected running
time of any algorithm which will only tell the professor they have all been in the
room once they have actually all been there must take at least (n lg n) days.
Hence, E[time] = (n lg n).
CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #3 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.
If we ask for an answer in terms of n and d, please give the answer in terms of n and
d and do not assume that d is a constant. Many people did this on the first problem
as well as the skip list problem from the last problem set.
In part (b) of problem 3, many people only showed that the probability that any slot
had k elements was nQk . You had to show the maximum number of elements was
k.

1. [14 points] Analysis of d-ary Heaps


Throughout this problem, when asked to give an implementation of a certain operation,
please provide pseudocode or a verbal description with the same level of clarity and
detail. When asked to analyze running times, your analysis does not need to be formal,
but should be justified.
Note that we are asking you to solve 6-2(e) before 6-2(d). Keep in mind that you may
always (not only in this problem) use the results of any previous parts in answering a
later part of a multi-part problem.

(a) [1 point] Do problem 6-2(a) on page 143 of CLRS.


Answer: A d-ary heap can be represented in a 1-dimensional array by keeping
the root of the heap in A[1], its d children in order in A[2] through A[d + 1], their
children in order in A[d + 2] through A[d2 + d + 1], and so on. The two procedures
that map a node with index i to its parent and to its j th child (for 1 j d) are

D-PARENT(i)
1 return d(i 1)/de

D-CHILD(i, j)
2 return d(i 1) + j + 1

(b) [1 point] Do problem 6-2(b) on page 143 of CLRS.


Answer: Since each node has d children, the total number of nodes in a tree
of height h is bounded above by 1 + d + . . . + dh inclusively and below by
1 + d + . . .+ dh1 exclusively. This yields h = dlogd (1 + n(d 1))e 1 = (logd n).
Problem Set #3 Solutions 2

(c) [2 points] Give an efficient implementation of HEAPIFY in a d-ary max-heap.


Analyze its running time in terms of d and n.
Answer: First, we will need to find if the root element given to D-HEAPIFY is
larger than all its children. If not, we swap it with its largest child and recursively
call D-HEAPIFY on that child.

D-HEAPIFY(A, i, d)
1 largest i
2 for j 1 to d
3 j D-CHILD(i, j)
4 if j heapsize[A] and A[j] > A[largest]
5 then largest j
6 if largest 6= i
7 then exchange A[i] A[largest]
8 D-HEAPIFY(A, largest, d)

This algorithm does (d) comparisons in each call to D-HEAPIFY as well as


O(logd n) calls to HEAPIFY, one for each level of the tree. Therefore, the total
running time for this algorithm is O(d logd n).
(d) [5 points] Give an efficient implementation of BUILD-HEAP in a d-ary max-
heap. Analyze its running time in terms of d and n.
Answer: To build a heap, we can simply assume that our array is already a heap
and call D-HEAPIFY in a bottom up manner to convert the array into a d-max-
heap. The leaves are already heaps since they have no children, so we start with
the lowest non-leaf element. By our procedure for D-PARENT, the parent of the
last element is d(n 1)/de. By the time we call D-HEAPIFY on any element,
D-HEAPIFY will have already been called on all of its children and therefore the
call is valid since the children are all themselves heaps.

D-BUILD-HEAP(A, d)
1 heapsize[A] length[A]
2 for i d(length[A] 1)/de downto 1
3 do D-HEAPIFY(A, i, d)

We can bound the running time of this algorithm by modifying the analysis in
section 6.3 of CLRS. Notice that there are

dlogd (n(d1))(h+1) = dlogd (


n(d1)
dh+1
) = n(d 1)
dh+1
nodes at each height h. From part (c), the time for each call to HEAPIFY at a
node of height h is O(dh). So, the running time
Problem Set #3 Solutions 3

lgd (n(d1))
X n(d 1)
T (n) dh
dh+1
h=0

X h
< n(d 1)
h=0
dh
1/d
n(d 1) A.8
(1 1/d)2
d
= n
d 1 
1
= n 1+
d1

For any d 2 we have 1 1 + 1/(d 1) 2, so T (n) = (n).


(e) [2 points] Do problem 6-2(c) on page 143 of CLRS.
Answer: The procedure D-EXTRACT-MAX is the same as for the binary heap.
We return the value of A[1], move the element in A[heapsize] into A[1], decrement
heapsize, and then call D-HEAPIFY on the root of the heap.

D-EXTRACT-MAX(A, d)
1 if heapsize[A] < 1
2 then error
3 max A[1]
4 A[1] A[heapsize]
5 heapsize heapsize 1
6 D-HEAPIFY(A, 1, d)
7 return max

All operations besides D-HEAPIFY take O(1) time. D-HEAPIFY takes time
(d logd n) so D-EXTRACT-MAX takes time (d logd n).
(f) [2 points] Do problem 6-2(e) on page 143 of CLRS.
Answer: If k < A[i], then D-INCREASE-KEY does not change the heap.
Otherwise, it will set A[i] to k and move the element upwards toward the root
until it is smaller than its parent.

D-INCREASE-KEY(A, i, k, d)
1 if k > A[i]
2 then A[i] k
3 while i > 1 and A[D-PARENT(A, i, d)] < A[i]
4 do exchange A[i] A[D-PARENT(A, i, d)]
5 i A[D-PARENT(A, i, d)]
Problem Set #3 Solutions 4

The running time of the algorithm is proportional to the height of the heap, and
each level takes a constant amount of work, so the overall time is (logd n).
(g) [1 point] Do problem 6-2(d) on page 143 of CLRS.
Answer: The procedure D-INSERT is the same as for the binary heap. We
add the element to the end of the array and set its key to . Then, we call
D-INCREASE-KEY to increase to increase the key to key.

D-INCREASE-KEY(A, key, d)
1 heapsize[A] heapsize[A] + 1
2 A[heapsize[A]]
3 D-INCREASE-KEY(A, heapsize[A], key, d)

The first two operations take constant time, and the call to D-INCREASE-KEY
takes time (logd n). So, the running time for D-INCREASE-KEY is (logd n).

2. [23 points] Average-Case Lower Bounds on Comparison Sorting


Throughout the next two problems, when asked to prove, argue, show or conclude
something, please make your explanations as clear and complete as possible.

(a) [4 points] Do problem 8-1(a) on page 178 of CLRS.


Answer: Since the sort can be run on any input, the algorithm must be able to
reach any permutation of the input in order to get the correct sorted order as an
answer. Because A is deterministic, any input will always follow exactly one path
in TA . There are n! possible permutations of n elements, and each permutation
should lead to a distinct leaf in TA in order to yield the correct sorted order.
Since we assume that every permutation of As input is equally likely and since
the probabilities must sum to 1, each leaf must have probability 1/n!. Any other
leaf is never reached and thus must have probability 0, as needed to be shown.
(b) [2 points] Do problem 8-1(b) on page 178 of CLRS.
Answer: The external path length T is given by the sum of the depths of all the
leaves contained in the right subtree plus the sum of the depths of all the leaves
contained in the left subtree. The sum of the depths of the leaves in the right
subtree is the sum of the depths up to the root of the right subtree plus one for
each leaf in the right subtree, and likewise for the sum of the depths in the left
subtree. So, the total depth D(T ) = D(RT )+ number of leaves in RT + D(LT )
+ number of leaves in LT . Each leaf must be in exactly one of the left or right
subtrees, so D(T ) = D(RT ) + D(LT )+ number of leaves = D(RT ) + D(LT ) + k.
(c) [3 points] Do problem 8-1(c) on page 178 of CLRS.
Answer: Consider a decision tree T with k leaves that achieves the minimum.
Let i0 be the number of leaves in LT and k i0 be the number of leaves in RT .
From part (b), we have D(T ) = D(LT ) + D(RT ) + k. Notice that this implies
that LT and RT also have the minimum external path length over all subtrees
Problem Set #3 Solutions 5

with i0 and k i0 leaves respectively, since otherwise we could replace them with
better trees and get a lower value of D(T ).
Finally, the optimal tree T represents the best possible split of the k leaves into
(optimal) subtrees with i0 and k i0 leaves. Since each subtree must have at least
one leaf, we have d(k) = min1ik1 {d(i) + d(k i) + k}.
(d) [4 points] Do problem 8-1(d) on page 178 of CLRS.
Answer: We can find the minimum by setting the derivative with respect to i
equal to zero.

d
(i lg i + (k i) lg(k i)) = (i)(1/i)(lg e) + (1)(lg i) +
di
(k i)(1/(k i))( lg e) + (1)(lg(k i))
= lg e + lg i lg e lg(k i)
= lg i lg(k i)

This is zero when i = k i or i = k/2. We can verify that this is in fact a


minimum by taking the second derivative and checking that it is positive.

We can now check that d(k) = (k lg k) using the guess-and-check method.


Assume that d(i) ci lg i for i < k.

d(k) = min (d(i) + d(k i) + k)


1ik1
min (ci lg i + c(k i) lg(k i) + k)
1ik1
= k + c min {i lg i + (k i) lg(k i)}
1ik1
k + c((k/2) lg(k/2) + (k/2) lg(k/2))
= ck lg(k/2) + k
= ck(lg k lg 2) + k
= ck lg k + k(1 c)
ck lg k

with the last inequality holding as long as c 1. Therefore, d(k) = (k lg k).


(e) [2 points] Do problem 8-1(e) on page 178 of CLRS.
Answer: In part (a), we showed that any deterministic tree TA has at least n!
leaves. Since d(k) is the minimum value over all decision trees with k leaves, we
know that D(TA ) d(k). In part (d), we showed that d(k) = (k lg k). Since TA
has k n! leaves, we know D(TA ) d(k) = (k lg k) = (n! lg(n!)).
The expected time to sort n elements is the sum over all leaves of the length
of the path to that leaf times the probability of reaching that leaf. Since the
probability of reaching each leaf is 1/n! (ignoring leaves with probability 0 that
Problem Set #3 Solutions 6

contribute nothing to the sum), this is precisely D(TA )/n!. Thus, E[T (n)] =
(n! lg(n!))/n! = (lg n!) = (n lg n).
(f) [8 points] Do problem 8-1(f) on page 178 of CLRS.
Answer: Consider the decision tree TB for algorithm B. We will work from the
bottom to the top, replacing each randomization node with the branch that has
the smallest external path length. We call the resulting tree TA and we show that
TA represents a valid deterministic sorting algorithm and E[TA (n)] E[TB (n)].
First, consider the issue of correctness. Since the decision tree for A represents a
possible execution of B (with appropriate random choices made at each step), and
B is correct, the resulting decision tree must represent a valid sorting algorithm.
Since all randomization nodes have been removed, this algorithm is deterministic.
Now notice that at each randomizationPnode N, the expected execution time
r th
after that node is reached is equal to i=1 (1/r)E[T (Si )], where Si is the i
subtree of N. Clearly we have E[T (N)] minri=1 E[T (Si )], since all terms in the
average must be at least the minimum. Thus, each transformation that replaces
a randomization node with its best child does not increase the expected running
time.
We formalize these notions slightly. Consider a sequence of decision trees
T1 , . . . , Tm where T1 = TB and Tm = TA , and each Ti was obtained from Ti1
by choosing a randomization node all of whose descendants are deterministic
and replacing it with the subtree with the smallest external path length. Notice
that since no descendants of N are randomization nodes, the notion of expected
running time and external path length (given random input) is the same for its
children.
The correctness argument above applies, as does the running time argument:
E[T (Ti )] E[T (Ti1 )]. Finally, when all the randomization nodes are removed,
we have a deterministic sorting algorithm with the decision tree Tm = TA and
expected running time no worse than the expected running time of B.

3. [18 points] Slot-Size Bound for Chaining

(a) [2 points] Do problem 11-2(a) on page 250 of CLRS.


Answer The probability that exactly k keys hash to the same spot is given by
first choosing k keys from the n, multiplying by the probability that those k keys
hashed to a particular spot, and multiplying by the probability that the remaining
n k keys hashed to a different spot (see appendix C.4 for a discussion of the
binomial distribution if this is unclear). Thus we have
 k  nk  
1 1 n
Qk = 1 .
n n k
(b) [2 points] Do problem 11-2(b) on page 250 of CLRS.
Answer: The probability of the event M = k is equal to P r{ni=1Ei }, where Ei
is the event that slot i has the maximum number of elements and that slot i has
exactly k elements.
Problem Set #3 Solutions 7

The probability of a union of a set of events is bounded by the sum of the


probabilities of those events (with
Pn equality if and only if those events are mutually
exclusive), so P r{M = k} i=1 P r{Ei} = nP r{E1 } due to symmetry.
Finally, observe that the event Ei subsumes the event that exactly k keys hash to
slot i, because Ei represents the event { k keys hash to i and i has the maximum
number of elements}. Thus, P r{Ei} Qk . Combining this with the previous
equation yields
Pk = P r{M = k} nP r{E1 } nQk .
(c) [2 points] Do problem 11-2(c) on page 250 of CLRS.
Answer:
 k  nk  
1 1 n
Qk = 1
n n k
 k    nk
1 n 1
since 1 1
n k n
 k  
1 en k
equation C.5
n k
 e k
=
k

(d) [8 points] Do problem 11-2(d) on page 250 of CLRS.


Answer: We will find a c > 1 such that (e/k0 )k0 < 1/n3 . Since (e/k)k is a
decreasing function for k > e (when e/k < 1), this means that Qk < 1/n3 for
k k0 . Finally, combining this with the result of part (b) will yield the desired
bound on Pk .
Thus, we want (e/k0 )k0 < 1/n3 . Taking lg of both sides yields

 
e
k0 lg < 3 lg n
k0
k (lg e lg k0 ) < 3 lg n
 0 
c lg n c lg n
lg e lg < 3 lg n
lg lg n lg lg n
c
(lg e lg c lg lg n + lg lg lg n) < 3
lg lg n
c
( lg e + lg c + lg lg n lg lg lg n) > 3
lg lg n

For c > e, the lg c term is larger than the lg e term, so we need to make sure the
rest of the left side is greater than the right side, i.e.
Problem Set #3 Solutions 8

c
(lg lg n lg lg lg n) > 3
lg lg n
3 lg lg n
c >
lg lg n lg lg lg n
3
c > lg lg lg n
1 lg lg n

As n gets large, the second term in the denominator will go to zero; in fact for
n 16 we have lglglglglgnn 1/2 so the right hand side is 6.
Thus, we can choose an appropriate constant c to guarantee that (e/k0 )k0 < 1/n3
and therefore Qk < 1/n3 for k k0 . Thus, Pk nQk < 1/n2 for k k0 .
(e) [4 points] Do problem 11-2(e) on page 250 of CLRS.
Answer:

n
X
E[M] = i P r{M = i}
i=1
Xk0 n
X
= i P r{M = i} + i P r{M = i}
i=1 i=k0 +1
k0
X n
X
k0 P r{M = i} + n P r{M = i}
i=0 i=k0 +1
= k0 P r{M k0 } + nP r{M > k0 }
   
c lg n c lg n c lg n
= n Pr M > + Pr M
lg lg n lg lg n lg lg n

Plugging in the values from part (d), we have

c lg n
E[M] (n)(n k0 )(1/n2 ) + 1
lg lg n
c lg n
(n)(n)(1/n2 ) +
lg lg n

Thus, E[M] 1 + c lg n/ lg lg n = O(lg n/ lg lg n).


CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #4 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.

On problem 1(f), many people assumed that if the key[y] < key[x] then y was in the
left subtree of x or that if priority[y] < priority[x] then y was a child of x. These
stipulations are not true, since in either case you can also have y not be a descendant
of x and the condition may still hold. Also, many people did not prove both the if and
the only if parts of the statement.

For augmented red-black trees in general, if the augmentation does not satisfy Theorem
14.1, you should show that it can be maintained efficiently through insertion, deletion,
and rotations.

On problem 5(b), a common mistake was to sort by the x indices, but to not take into
account the order for equal x index. For equal xi s, you need to sort by decreasing
index yj so that you can match at most one yj to each xi .

1. [34 points] Treaps


Throughout this problem, please be as formal as possible in your arguments whenever
asked to show or conclude some result.

(a) [4 points] Do problem 13-4(a) on page 297 of CLRS.


Answer: Our proof is inductive and constructive. The induction is on the number
of elements in the treap. The base case of 0 nodes is the empty treap. We now
suppose that the claim is true for 0 k < n nodes, and show it is true for
n. Given a set of n nodes with distinct keys and priorities, the root is uniquely
determined - it must be the node with the smallest priority in order for the min-
heap property to hold. Now suppose this root node has key r. All elements with
key < r must be in the left subtree, and all elements with key > r must be in the
right subtree. Notice that each of these sets has at most n 1 keys, and therefore
has a unique treap by the inductive assumption. Thus, for the n-node treap, the
root is uniquely determined, and so are its subtrees. Therefore, the treap exists
and is unique.
Notice this suggests an algorithm for finding the unique treap: choose the element
with the smallest priority, partition the remaining elements around its key, and
recursively build the unique treaps from the elements smaller than the root key
Problem Set #4 Solutions 2

(these will go in the left subtree) and the elements larger than the root key (right
subtree).
(b) [2 points] Do problem 13-4(b) on page 298 of CLRS.
Answer: Recall from lecture and section 12.4 of CLRS that the expected height
of a randomly built binary search tree is O(lg n). We show that constructing the
unique treap is equivalent to inserting the elements into a binary search tree in
random order.
Suppose we insert the elements into a BST in order of increasing priority. Normal
BST insertion will maintain the binary search tree property, so we only need to
show that the min-heap property is maintained on the priorities. Suppose v is a
child of u. The insertion procedure from section 12.3 of CLRS always inserts each
element at the bottom of the tree, therefore v must have been inserted after u.
Thus, the priority of v is greater than the priority of u, and we have built a treap.
The priorites are assigned randomly, which means any permutation of the
priorities is equally likely. When considering this as BST insertion, it translates
into any ordering being equally likely, and therefore the expected height of a treap
is equal to the expected height of a randomly built BST, which is O(lg n).
(c) [6 points] Do problem 13-4(c) on page 298 of CLRS.
Answer: Treap-Insert works by first inserting the node according to its key and
the normal BST insertion procedure. This is guaranteed to maintain the first two
conditions of the treap, since those correspond to BST properties. However, we
may have violated the third condition, the min-heap ordering on the priorities.
Note that (initially) this violation is localized to the node were inserting and its
parent, since we always insert at the leaves. Rotations preserve BST properties,
so we will use rotations to move our node x up as long as the min-heap ordering
is violated, i.e. as long as priority[x] < priority[parent[x]]. If x is a left child we
will right-rotate it, and if its a right child we will left-rotate it. Notice that this
preserves the heap property elsewhere in the treap, assuming that the children
of x had higher priority than parent[x] prior to the rotation (to be completely
formal we would have to prove this using a loop invariant).
The pseudocode is as follows:
TREAP-INSERT(T, x, priority)
1 TREE-INSERT(T, x)
2 while parent[x] 6= NIL priority[x] < priority[parent[x]]
3 if lef t[parent[x]] == x
4 Right-Rotate(T, parent[x])
5 else
6 Left-Rotate(T, parent[x])
(d) [2 points] Do problem 13-4(d) on page 298 of CLRS.
Answer: TREAP-INSERT first performs a BST insert procedure which runs in
time proportional to the height of the treap. Then, it rotates the node up one
level until the min-heap property is satisfied. Thus, the number of rotations we
perform is bounded by the height of the treap. Each rotation takes constant
Problem Set #4 Solutions 3

time, so the total running time is proportional to the height of the treap, which
we showed in (b) to be expected (lg n).
(e) [4 points] Do problem 13-4(e) on page 298 of CLRS.
Answer: We will prove this using a loop invariant: after having performed k
rotations during the insertion of x, Ck + Dk = k.
Initialization: After we insert x using BST-INSERT but before performing any
rotations, x is a leaf and its subtrees are empty, so C0 = D0 = 0.
Maintenance: Assume that we have performed k rotations on x and that Ck +Dk =
k. Now, if we perform a right-rotation on x, the left child of x remains the same,
so Ck+1 = Ck . The right child of x changes from to y with subtrees (left)
and (right) using the notation from page 278. The left spine of the right child
used to be the left spine of and now it is y plus the left spine of . Therefore,
Dk+1 = Dk + 1. Thus, Ck+1 + Dk+1 = Ck + Dk + 1 = k + 1, which is precisely the
number of rotations performed. The same holds for left-rotations, where we can
show that Dk+1 = Dk and Ck+1 = Ck + 1.
Termination: After TREAP-INSERT is finished, the number of rotations we
performed is equal to C + D, precisely the condition that needed to be shown.
(f) [5 points] Do problem 13-4(f) on page 298 of CLRS.
Answer: First, assume Xi,k = 1. We will prove priority[y] > priority[x],
key[y] < key[x], and z such that key[y] < key[z] < key[x], we have priority[y] <
priority[z]. The first property follows from the min-heap property on priorities,
since y is a descendant of x. The second follows from the BST property,
since y is in the left subtree of x. Finally, consider any node z satisfying
key[y] < key[z] < key[x], and imagine an inorder tree walk on the treap. After
y is printed, we will print the right subtree of y, at which point the entire left
subtree of x will have been printed since y is in the right spine of that subtree.
Thus, the only nodes printed after y but before x are in the right subtree of
y; therefore, z must be in the right subtree of y and by the min-heap property
priority[y] < priority[z].
Now, we will assume the three properties and prove that Xi,k = 1. First consider
the possibility that y is in the left subtree of x but not in the right spine of
that subtree. Then there exists some node z in the spine such that going left
from z will lead to y. Note that this z satisfies key[y] < key[z] < key[x], but
priority[z] < priority[y] which violates the third property. Clearly y cannot be
in the right subtree of x without violating the second property, and x cannot be
a descendant of y without violating the first property. Suppose that x and y are
not descendants of each other, and let z be their common ancestor. Again we
have key[y] < key[z] < key[x] but priority[z] < priority[y], violating the third
property. The only remaining possibility is that y is in the right spine of the left
subtree of x, i.e. Xi,k = 1.
(g) [4 points] Do problem 13-4(g) on page 300 of CLRS.
Answer: Assume that k > i. P r{Xi,k = 1} is the probability that all the
conditions in part (f) hold. Consider all the elements with keys {i, i + 1, . . . , k}.
Problem Set #4 Solutions 4

There are k i + 1 such elements. The values of their priorities can be in any
order, so there are (k i + 1)! possible (and equally likely) permutations. In order
to satisfy our conditions, we need priority[z] > priority[y] > priority[x] for all
z {i + 1, i + 2, . . . , k 1}. This fixes the priorities of x and y to be the lowest
two priorities, allowing (k i1)! permutations of the remaining priorities among
the elements with keys in {i + 1, . . . , k 1}. The probability of Xi,k = 1 is the
(ki1)!
ratio of these two, which gives P r{Xi,k = 1} = (ki+1)! . Most of the terms in
the factorials will cancel, except for the first two terms in the denominator. This
1
leaves us with P r{Xi,k = 1} = (ki+1)(ki) .
(h) [3 points] Do problem 13-4(h) on page 300 of CLRS.
Answer: The expected value for C, which is the number of elements in the right
spine of the left subtree of x is simply the expectation of the sum of Xi,k over all
i < k. This is

Xk1
E[C] = E[ Xi,k ]
i=1
k1
X
= E[Xi,k ]
i=1
k1
X
= P r[Xi,k = 1]
i=1
k1
X 1
=
i=1
(k i + 1)(k i)
1 1 1
= + ++
(k)(k 1) (k 1)(k 2) (2)(1)
k1
X 1
=
(j + 1)(j)
j=1
k1  
X 1 1
=
j=1
j j+1
1 1
=
1 k
1
= 1
k

(i) [2 points] Do problem 13-4(i) on page 300 of CLRS.


Answer: Note that the expected length of the right spine of the left subtree of
x depends only on the rank k of the element x. The expected length of the left
spine of the right subtree will have the same expected value with respect to the
1
rank of x in the reverse ordering, which is n k + 1. Thus, E[D] = 1 nk+1 .
Problem Set #4 Solutions 5

(j) [2 points] Do problem 13-4(j) on page 300 of CLRS.


Answer: Since the number of rotations equals C + D, the expected number of
rotations equals E[C + D] = E[C] + E[D] = 1 k1 + 1 nk+1
1
2. So, the
expected number of rotations is less than 2.

2. [32 points] Augmenting Data Structures


Throughout this problem, your explanations should be as complete as possible. In
particular, if you use an augmented data structure that is not presented in the textbook,
you should explain how that data structure can be efficiently maintained, explain how
new operations can be implemented, and analyze the running time of those operations.
If the problem asks you to give an algorithm, you do not need to give pseudocode or
formally prove its correctness, but your explanation should be detailed and complete,
and should include a running time analysis.

(a) [9 points] Do problem 14.1-8 on page 308 of CLRS.


Answer: To solve this problem, we will first define some kind of coordinate
system. This can be done by picking an arbitrary nonendpoint starting point
on the circle and setting it to zero and defining clockwise as positive values (for
example, number of degrees from the starting point). We can label each chords
endpoints as Si , Ei where the start endpoint has lower value. We then notice that
to count the chords which intersect a particular chord i, we can count the chords
which have only one endpoint between Si and Ei . Since well then double-count
the number of intersections, well just count those intersections that are in the
forward direction, namely the chord has its start endpoint in Si , Ei , but not its
other endpoint. The chords which have their end endpoints in the interval will
count i as intersecting them.
We can then use an order-statistic red-black tree to help us count the number
of intersections. We will first sort the endpoints according to our coordinate
system. Since there are n chords each with 2 endpoints, this step will take
(2n lg 2n) = (n lg n). We then process the endpoints according to their sorted
values, starting with the smallest. If it is a start endpoint, we insert it into
the order-statistic tree ((lg n)). If it is an end endpoint, we want to count
the number of start endpoints we have seen without matching end endpoints. If
we delete start endpoints as we see their corresponding end endpoints, we will
maintain the property that all the nodes in our tree are open chords, ones which
we can still intersect. So, for each end endpoint, we delete the corresponding
start endpoint and then count the number of open endpoints left in the tree - this
will be precisely the number of chords that have their starting endpoint between
Si and Ei but have their end endpoint after Ei . Thus, we add this number to
a counter and delete the start endpoint of that chord (each end endpoint can
have a pointer to its start). This step takes (lg n) for the deletion and (1) to
figure out the number of forward intersections for the chord. We proceed like this
through all the endpoints. Since each endpoint takes time (lg n) to insert or
delete from the tree, the total running time of this step is ((n lg n).
Problem Set #4 Solutions 6

After processing all endpoints, we will have a count of the number of intersections
inside the circle. The total running time is the time to sort plus the time to insert
and delete from the OS-tree, both of which are (n lg n). Therefore, the total
running time is (n lg n).
(b) [4 points] Do problem 14.2-1 on page 310 of CLRS.
Answer: We can find the SUCCESSOR and PREDECESSOR of any node x in
time (1) by storing pointers to the successor and predecessor of x inside the
node structure. Note that these values do not change during rotations, so we only
need to show that we can maintain them during insertions and deletions.
As soon as we insert a node x, we can call the regular TREE-SUCCESSOR(x)
and TREE-PREDECESSOR(x) functions (that run in O(lg n)) to set its fields.
Once the successor and predecessor are determined, we can set the appropriate
fields in x, and then update the SUCC field of the predecessor of x and the PRED
field of the successor of x to point to x. When we delete a node, we update its
successor and predecessor to point to each other rather than to x. To simplify the
handling of border cases (e.g. calling SUCCESSOR on the largest element in the
tree), it may be useful to keep a dummy node with key and a dummy node
with key +.
Finally, MINIMUM and MAXIMUM (which are global properties of the tree)
may be maintained directly. When we insert a node, we check if its key is
smaller than the current minimum or larger than the current maximum, and
update the MINIMUM and/or MAXIMUM pointer if necessary. When we delete
a node, we may need to set MINIMUM and/or MAXIMUM to its successor and/or
predecessor, respectively, if we are deleting the minimum or maximum element in
the tree.
Thus, these operations run in (1) and may be maintained without changing the
asymptotic running time of other tree operations.
(c) [5 points] Do problem 14.2-5 on page 311 of CLRS.
Answer: Using our answer from the previous part where we showed how to
maintain SUCCESSOR and PREDECESSOR pointers with O(1) running time,
we can easily perform RB-ENUMERATE.

RB-ENUMERATE(x, a, b)
1 start TREE-SEARCH(x, a)
2 if start < a
3 then start SUCC[start]
4 while start b
5 print start
6 start SUCC[start]

We must modify TREE-SEARCH to return the smallest element greater than or


equal to a rather than NIL if a is not in the tree.
This algorithm finds and outputs all the elements between a and b in x. The
Problem Set #4 Solutions 7

TREE-SEARCH operation takes time lg n where n is the number of nodes in the


tree. The while loop runs m times where m is the number of keys which are
output. Each iteration takes constant time since finding the SUCCESSOR of a
node now takes constant time. Therefore, the total running time of the algorithm
is (m + lg n).
We can also answer this question without resorting to augmenting the data
structure: we perform an inorder tree walk, except we ignore (do not recurse
on) the left children of nodes with key < a and the right children of nodes with
key > b. Thus, if we consider both children of a node we will output at least one
of them, therefore, all nodes not counted by m will lie on two paths from the root
to a leaf in the tree. This yields a total running time of (m + lg n) as before.
(d) [6 points] Do problem 14.3-6 on page 317 of CLRS. You may assume that all
elements of Q will always be distinct.
Answer: We can keep an augmented red-black tree of the different elements in
Q. Each node x in the tree will be augmented with the following three fields:
i. mingap[x] is the minimum different between two nodes in the subtree rooted
at x. If x is a leaf, mingap[x] is .
ii. max[x] is the maximum key value in the subtree rooted at x.
iii. min[x] is the minimum key value in the subtree rooted at x.
We can efficiently calculate these fields based simply on the node x and its
children.

min[lef t[x]] if left child exists
min[x] =
key[x] otherwise

max[right[x]] if right child exists
max[x] =
key[x] otherwise


mingap[lef t[x]] if left child exists
mingap[right[x]] if right child exists



mingap[x] = min key[x] max[lef t[x]] if left child exists
min[right[x]] key[x] if right child exists






Notice that to calculate the mingap of a node x, we compare the mingaps of the
subtrees rooted at the children as well as the two possible minimum gaps that x
can have, namely where you subtract x from the smallest element largest than it
and where you subtract the largest element smaller than x from x.
All three fields depend only on the node x and its children so we can efficiently
maintain them through insertion, deletion, and rotation according to theorem 14.1
in CLRS. Notice that we keep the min and max values so that we can calculate
mingap using only information from the node and its children.
The running time of the insert and delete operations are the same as for the red-
black tree and are (lg n). The procedure MinGap(Q) can simply look in the
root node and return the mingap field which holds the minimum gap in the tree.
Thus, the running time for MinGap is O(1).
Problem Set #4 Solutions 8

(e) [8 points] Do problem 14-1(b) on page 318 of CLRS. You may assume the result
of 14-1(a) without proof.
Answer: We know from part (a) that the point of maximum overlap is the
endpoint of one of the intervals. So, we wish to find the endpoint which is the
point of maximum overlap. To do this, we will follow the hint and keep a red-
black tree of the endpoints of the intervals. With each node x, we will associate
a field v[x] which equals +1 if x is a left endpoint and 1 if x is a left endpoint.
We will also augment each node with some additional information to allow us to
find the point of maximum overlap efficiently.
First, we will provide some intuition. If x1 , x2 , . . . , xn are the sorted sequence of
endpoints of the intervals, then if we sum from i = 1 to j of v[xi ], we find precisely
the number of intervals which overlap endpoint j (this assumes our intervals are
half-open of the form [a, b)). So, the point
Pj of maximum overlap will be the value
of j which has the maximum value of i=1 v[xi ].
We will augment our red-black tree with enough information to calculate the point
of maximum overlap for the subtrees rooted at each node. The point of maximum
overlap depends on the cumulative sum of the values of v[x]. So, in addition to
each v[x], we will keep a variable SUM[x] at each node which is the sum of the
v[i] values of all the nodes in xs subtree. Also, we will keep a variable MAX[x]
which is the maximum possible cumulative sum of v[i]s in the subtree rooted
at x. Finally, we will keep P OM[x] which is the endpoint xi which maximizes
the MAX expression above. Clearly, P OM[root] will be the point of maximum
overlap on the entire set of intervals.
We will demonstrate how to compute these fields using only information at
each node and its children. Therefore, by theorem 14.1, we can maintain this
information efficiently through insertions, deletions, and rotations. The sum of
the v[i] of the subtree rooted at node x will simply be
SUM[x] = SUM[lef t[x]] + v[x] + SUM[right[x]].
The maximum cumulative sum can either be in the left subtree, x itself, or in the
right subtree. If it is in the left subtree, it is simply MAX[lef t[x]]. If it is x, the
cumulative sum till x is SUM[lef t[x]] + v[x]. If it is in the right subtree, we have
to add the cumulative sum up till the right subtree to the max value of the right
subtree, SUM[lef t[x]] + v[x] + MAX[right[x]].
MAX[x] = max(MAX[lef t[x]], SUM[lef t[x]] + v[x], SUM[lef t[x]] + v[x] +
MAX[right[x]])
The point of maximum overlap is the value of the node which maximized the above
expression. (l[x] and r[x] refer to the left and right children of x respectively)

P MO[l[x]] if MAX[x] = MAX[l[x]]
P MO[x] = x if MAX[x] = SUM[l[x]] + x
P MO[r[x]] if MAX[x] = SUM[l[x]] + x + MAX[r[x]]

So, since each just depends on itself and its children, Interval-Insert and Interval-
Delete will run in time (lg n) since we either insert or delete 2 nodes from the
tree. At any time, P MO(root) will hold the point of maximum overlap and
Problem Set #4 Solutions 9

MAX(root) will return how many intervals overlap it. Thus, the operation Find-
PMO can be performed in (1) time.

3. [15 points] Dynamic Programming: Optimization

(a) [7 points] You are planning a cross-country trip along a straight highway with
n + 1 gas stations. You start at gas station 0, and the distance to gas station i
is di miles (0 = d0 < d1 < . . . < dn ). Your cars gas tank holds G > 0 gallons,
and your car travels m > 0 miles on each gallon of gas. Assume that G, m, and
all di are integers. You start with an empty tank of gas (at gas station 0), and
your destination is gas station n. You may not run out of gas, although you may
arrive at a gas station with an empty tank. The price of gas at gas station i is pi
dollars per gallon (not necessarily an integer). You cannot sell gas.
Give an algorithm to calculate the cost of the cheapest possible trip. State
the running time and space usage of your algorithm in terms of the relevant
parameters.
Answer: We will solve this problem using dynamic programming by noting that
if we knew the optimal way to leave gas station i 1 with any amount of gas in
the tank, then we could easily calculate the optimal way to leave gas station i
with any amount of gas in the tank. We could do this by taking the minimum
over the cost of leaving gas station i 1 plus the cost of however much gas wed
need to put in the tank at gas station i. Notice that the amount of gas in the
tank times m must be an integer in the range from 0 to mG since the distances
we travel are given by gas/m and are all integers. From now on, we will call these
values of gas m units of gas. So, we can build a table T which is mG by n.
We initialize the first row of the table by noticing that the only way to leave gas
station 0 with k units of gas is to fill up k units of gas at gas station 0. This has
a cost of (p0 k)/m. So, our base case of the table T is

T [0, k] = (p0 k)/m.

We can then define each additional row in terms of a minimum over the previous
row. For example, lets say we want to get to gas station i with no units of gas
in the tank. There is only one way to do that since we cant sell gas. We must
leave gas station i 1 with exactly enough gas to get to gas station i. This
distance is di di1 , and the amount of gas necessary is (di di1 ) m, so our
units of gas are exactly the distance, di di1 . So, the value of T [i, 0] is equal to
T [i 1, di di1 ]. Lets now consider the case where we want to get to gas station
i with 1 unit of gas in the tank. There are two ways we can acheive this. Either
we can leave gas station i 1 with one more unit of gas in the tank or we can
leave with exactly enough gas to get to i and buy one unit of gas at gas station
i. T [i, 1] = min(T [i 1, di di1 + 1], T [i 1, di di1 ] + (pi 1)/m). In general,
we take the minimum over many cells in the previous row. First, define i as the
distance between gas station i and i 1 so i = di di1 . We can calculate
Problem Set #4 Solutions 10

T [i, k] = mini k0 i +k T [i 1, k 0 ] + (pi (k 0 i ))/m

Some times we will look in the table for values that dont exists, for example when
k equals mG. Assume that T [i 1, k 0 > mG] will return infinity.
After filling the table, we will search in the row T [n, k] for the lowest value and
return that as the cheapest possible trip. Notice that this cheapest cell will always
be at T [n, 0] since any extra gas we have will have cost us something, and we may
as well not have bought it. Notice also that we can return the actual trip by
keeping pointers for each cell which point to the cell which caused the minimum.
For each cell in the table, we have to take a minimum over at most mG items.
Since there are n mG cells in the table, the running time for this algorithm
is (n(mG)2 ). The space requirement is the size of the table which is (nmG).
Since calculating each row in the table only depends on the previous row, we
can delete rows as we are finished processing them. So, we can reduce the space
requirement to (mG). However, if we wish to calculate the actual trip, we will
need to maintain the (nmG) table of pointers, which we arent able to delete,
since we dont know what our optimal trip is until after calculating the whole
table. So, in that case the space requirement remains at (nmG).
If we are clever in the way we update cells, we can actually reduce the running
time of the algorithm to (nmG) as well. Lets say we break the update to the
cells into two phases, before adding gas at station i and after adding gas at station
i. For the pre-fillup phase, we only have one way to arrive at a gas station with
a given amount of gas k, so we simply set each

T [i, k] = T [i 1, i + k]

where again we assume that T [i 1, k 0 > mG] = . For the post-fillup stage,
we can update each T [i, k] by looking at the cost of adding one unit of gas to
T [i, k 1], assuming T [i, k 1] already holds the minimum value to get there.

T [i, k] = T [i, k 1] + (pi 1)/m if that value is less than the current value in the
cell.

Since each cell now only looks back at a constant number of cells instead of O(mG)
cells, the running time is reduced to (nmG).
(b) [8 points] Do problem 15-7 on page 369 of CLRS.
Answer: Since there are so many variables in this problem, the first thing we
need to figure out is what our optimal subproblems are. We do this by considering
an optimal schedule over jobs a1 , . . . , aj that runs until time t. Assume that we
know which subset of jobs we perform to get the highest profit. What order do
we need to perform those jobs in? Notice that the job with the latest deadline
should be performed last. If we dont perform that job last, then we will waste
the time between the second last deadline and the last deadline. The same thing
Problem Set #4 Solutions 11

then applies for the second last deadline job being performed second last. We can
argue that the subset of jobs that we perform will be done in increasing order of
deadline.
This gives us our optimal subproblems. Namely, we order the jobs by increasing
deadline. When we consider job ai finishing at any time t (we assume these are
now in sorted order so it has the ith deadline) we can simply look back at the
optimal way to schedule the i 1 jobs and whether or not we add ai to the
schedule. We will also make the additional assumption that we leave no time
gaps between the jobs. It is easy to argue that if we have a schedule with time
gaps between jobs, we can also do the jobs in the same order with no time gaps
and receive the same profit and possibly more.
The actual algorithm is as follows. We keep a grid of the n jobs versus the time,
which can run up till dn (since the jobs are now sorted by deadline). Notice that
since the processing times are integers between 1 and n, the maximum time taken
to complete all the jobs is at most n2 . So, if we have any deadline which exceeds
n2 , we can simply replace it by n2 . Thus, our table is at most n n2 . Each cell in
the table i, j will represent the maximum profit possible for scheduling the first i
jobs in time exactly j, assuming that we have no gaps between our jobs.
We initialize the first row in the table by figuring out our possible profit based
on completing the first job at exactly time t. Since we assume no gaps in our
schedule, we must start the first job at time 0. Therefore, we will have a profit
of p1 in the cell at t1 if t1 d1 and a profit of zero otherwise. Well initialize all
other cells to zero. So, if we call our table T , we have

0 if t 6= t1
T [1, t] = p1 if t = t1 d1
0 if t = t1 > d1

Then, we can set the remaining cells in our table based simply on the previous
row. At each cell T [i, t], we have the choice of whether or not to perform job i. If
we decide not to perform job i, then our profit is simply T [i 1, t]. If we decide
to perform job i, then we know it takes ti units of time to complete it. So, we
must finish the previous jobs exactly at time t ti . We will get profit for the job
if t < di . We will pick the maximum profit from these two choices.

T [i 1, t]
T [i, t] = max T [i 1, t ti ] + pi if t di
T [i 1, t ti ] if t > di

At each cell, we will also keep a pointer to the cell which maximized the above
expression. After filling in the whole table, we can search through the T [n, t] row
for the highest profit. Then, we can follow the pointers back to find the schedule.
If in row i we take the pointer above us, we add i to the end of the schedule.
Otherwise, if we take the pointer that is diagonal, we say we complete i at that
time.
The running time of this algorithm is the number of cells in the table since each
cell takes a constant amount of time to evaluate. The search through the last row
Problem Set #4 Solutions 12

and following of the pointers both take time (n). Therefore, the running time
is (n3 ) if dn n2 and (ndn ) if dn < n2 .
The space requirement for this algorithm is the size of the table, which is the
same as the running time. Notice that since we want the actual schedule, we
cant compress the size requirement.

4. [15 points] Dynamic Programming: Counting and Games

(a) [7 points] Consider a chess knight on an n n chessboard. The knight may move
from any square (i, j) to (i0 , j 0 ) if and only if (|i0 i| , |j 0 j|) {(1, 2), (2, 1)} and
that square is on the board; in other words, the knight may move two squares in
one direction and one square in a perpendicular direction (see diagram).

Give an algorithm to calculate the number of ways in which the knight can travel
from square (is , js ) to (it , jt ) in exactly k 0 moves. State the running time and
space usage of your algorithm in terms of the relevant parameters.
Answer: We can calculate the solution to this problem by noticing that if we
knew the number of ways to get to every square on the board in k 1 moves from
the starting location, we could easily calculate the number of ways to get to a
square in k moves by simply summing over the atmost 8 squares that the knight
could move from. Each way to get to the predecessor in k 1 moves contributes
one way to get to the square in k moves.
Our DP matrix will be n n k. We initialize for all k = 0 the number of ways
to get to that square in 0 moves. Namely,
W ays(a, b, 0) = 1 if a = is AND b = js and zero otherwise. We can build
up our DP matrix for each 0 < i k from these values. For each value of
i = 1 . . . k, and P for each square (a, b) on the n n board, we set the value of
W ays(a, b, i) = (u,v)neighbors(a,b) W ays(u, v, i 1). The neighbors of a cell are
simply those that follow the condition given above for the legal knights moves.
At the end, we look at W ays(it, jt , k) to find the number of ways to get to (it , jt )
from (is , js ) in exactly k moves.
Notice here a trend common to DP problems. In order to solve how many ways
there are to get from a certain cell to another cell in k moves, we actually solve
Problem Set #4 Solutions 13

more than asked for. We figure out how many ways there are to get from the
start cell to every cell in k moves. While it seems like we do more computation,
this actually makes solving the next layer more efficient.
The running time of this algorithm will be proportional to the number of cells in
the matrix, since each cell takes a constant amount of time to calculate. Thus,
the running time is (n2 k). The amount of space is the same at (n2 k). Notice,
however, that to calculate the matrix for a given value of i we only use the values
at i 1. So, at any time, we dont need to store the entire n2 k matrix, we only
need two levels of it. If we delete levels (in k) as we finish using them, we only
need space (n2 ).
(b) [8 points] The cat and mouse game is played as follows: there is an n n board
with a cat in (initial) location (ic , jc ), a mouse in (initial) location (im , jm ), and a
piece of swiss cheese in location (is , js ).
Each cell (i, j) on the board has up to four neighbors: north (i, j + 1), south
(i, j 1), east (i + 1, j), and west (i 1, j). All four cells adjacent in this manner
are considered neighbors, except for the edges of the board and where there are
walls blocking some of the directions. Therefore, assume that for any given
cell (i, j) you have a list of zero to four neighboring cells NBR(i, j) specified as
you like (linked list, for example). You may assume the neighbor relationship is
symmetric, i.e. if (i0 , j 0 ) NBR(i, j), then (i, j) NBR(i0 , j 0 ) and vice versa.
The game alternates between the moves of the mouse, who moves first, and the
cat. The cheese does not move. If the mouse reaches the cheese before the cat
catches it (i.e. without ever entering the same cell as the cat), then the mouse
wins (the cheese endows the mouse with super powers). If the cat catches the
mouse before the mouse can reach the cheese, the cat wins. If both conditions are
satisfied simultaneously, i.e. the mouse enters a cell with the cat and the cheese
in it, the game is considered a draw. You may assume that if none of this occurs
within 2n2 moves, the game ends in a draw. Also, assume the cat and the mouse
must move every round.
Assume that the cat and mouse are infinitely intelligent, can see the entire board
and location of each other, and always make optimal decisions.
Give a dynamic programming algorithm to predict who will win the game. State
its running time (a good upper bound is sufficient) and space usage in terms of
n.
Answer: We can solve this problem by noticing that if the mouse knew the
outcome for each of his at most four possible moves, he would know which way
to go. If there was a move for which the mouse wins, hell choose that move and
win. If not, but theres a move for which the game is a draw, hell choose that
and draw. Otherwise, the cat wins for every move of the mouse, so we know the
cat wins. Similar reasoning holds for the cats strategy.
From this, we can see that our subproblems are who wins for each possible board
configuration, whose move it is, and which move were on. Since after 2n2 moves
the game ends in a draw, we know the base case of whether the cat wins, mouse
Problem Set #4 Solutions 14

wins, or a draw for the 2n2 move. We can define a set of boards for 2n2 + 1 which
have the cat winning if the cat and the mouse are on the same square not on the
cheese, the mouse winning if the mouse is on the cheese and the cat is elsewhere,
and a draw otherwise.
We need to keep track of all possible boards for each move k. A board position
consists of a cat position (n2 ) and a mouse position (n2 ), as well as whose turn
it is. Since the mouse goes first, we know that for odd k it is the mouses turn
and for even k it is the cats turn. We keep 2n2 possible sets of boards, each
corresponding to which move number we are on. We initialize the k = 2n2 board
as above, and work backwards.
For each 0 k < 2n2 and each of the n4 possible board configurations, we wish
to calculate who wins or if it is a draw. Our base cases are if the cat and the
mouse are on the same square not on the cheese, then the cat wins. If the cat
and the mouse are both on the same square as the cheese, then its a draw. And
if the mouse is on the cheese and the cat is elsewhere, then the mouse wins.
Otherwise, we look at the at most four possible board configurations in the k + 1
level corresponding to the possible moves. If k is odd (mouses turn) and there is
a possible board where the mouse wins, then we label this board as mouse, else
if there is a possible board where there is a draw, we label this board draw, else
we label this board cat. The symmetric case holds for k even (cats turn).
After filling out our (2n2 ) (n4 ) table, we look at the board in the k = 0 level
corresponding to the starting locations of the cat and mouse and give the label of
that board (cat, mouse, draw) as who wins the game.
Each cell looks at a constant number of other cells, so the running time of this
algorithm is (n6 ). The memory requirement is also (n6 ). Notice however that
we only need the k+1 boards to calculate the k boards. So, we need only store two
sets of board configurations at a time, leading to a space requirement of (n4 ).
We can actually achieve a running time of (n4 ) if we do our updates in an
intelligent manner. Rather than doing update move by move, we will initailiaze
our board (n2 n2 2 states) with the known terminal states (cat win, mouse
win, draw), and the rest will start out unknown. As some state is updated, it may
trigger up to four updates for its neighboring states. If we keep the states that
need to be updated in a data structure such as a queue, we can process them one
by one, doing a constant amount of work per update. We begin with neighbors
of the terminal states in the queue, and continue adding neighbors to the queue
for each update. The total number of updates done is at most the number of
states on the board, which yields a running time of O(n4 ). Any state that fails to
be updated when the queue is empty is then labeled as a draw state due to the
assumption that any game that lasts at least 2n2 moves will end in a draw.

5. [14 points] Dynamic Programming: Sequences and Sparse DP

(a) [6 points] Let X be a sequence x1 , . . . , xn with associated weights w1 , . . . , wn .


An increasing subsequence of t elements satisfies xj1 < . . . < xjt and its weight
Problem Set #4 Solutions 15

Pt
is i=1 wi . Describe a (n lg n) algorithm for finding the heaviest increasing
subsequence.
Answer: This problem is similar to the longest increasing subsequence problem,
where in that problem all elements had weight equal to 1. In that problem, we
were able to store the lowest value of the last element of a subsequence of length i
in an array L[i]. We showed in class that the L[i] array remained sorted. For each
element j in our sequence, we were able to perform a binary search in the L array
for the largest value smaller than j and update our array accordingly. This led to
a total running time of (n lg n) since each binary search took time (lg n).
In this case, we cant keep an array since the weights may not be integral values.
However, we can keep a red-black tree which will allow us to find elements in
time (lg n). Also notice that adding a single element may cause many previous
subsequences to never be used again. For example, if we have the sequence of
(key, weight) of (3, 3), (2, 2), (1, 1), (0, 5), we would find for the first three elements
a subsequence of weight 1 ending in key 1, one of weight 2 ending in key 2 and
one of weight 3 ending in key 3. Notice that all three of these subsequences may
still be part of our heaviest subsequence. But, when we add the fourth element
which gives a subsequence with weight 5 ending in key 0, none of the previous 3
subsequences can be part of our heaviest subsequence, since any time we could
append elements to those, we could append them to the subsequence ending in 0
and achieve a higher weight. Thus, in order to maintain only the useless sequences
we may now have to delete more than one element at a time.
Notice that the total number of elements deleted over the course of the algorithm is
n, which yields running time of O(n lg n). However, each particular update may
now take (n), so without this realization (which is a mild form of amortized
analysis) we do not have the desired bound with this approach.
The following is an alternative solution that uses augmented red-black trees. If
youre comfortable with counting the deletion time separate from insertion time
for the solution above, feel free to skip it. If you fear amortization like the plague,
read on.
So, for each key, we will wish to compute the heaviest subsequence
ending in that key. We will keep an augmented red-black tree of these
(key, weight of subsequence) pairs keyed on the key. We will refer to the weight
of the subsequence as ws , not to be confused with the weight of the element.
We will also keep pointers for each element of which element is its predecessor
in the heaviest subsequence ending in that element. At the end, we will search
through the tree for the highest weight and follow the pointers to find our heaviest
subsequence.
For each element i, we will need to find in the tree the node x with the highest
weight such that key[x] < key[i]. x is the node that we should append i onto to
get the heaviest increasing subsequence ending in i. To do this, we will augment
each node with W [x], the maximum weight of subsequences ending in elements
less than or equal to x in the subtree rooted at x. We can efficiently calculate W [x]
as max(W [lef t[x]], ws [x]). Since this property only depends on the values stored
Problem Set #4 Solutions 16

at node x and its children, we can maintain it during insertion, deletion, and
rotation. We will also keep at each node a pointer P [x] which points to the node
which attains that maximum weight. P [x] = P [lef t[x]] if W [lef t[x]] > weight[x]
and P [x] = x if weight[x] W [lef t[x]].
When we look at a new element i , we will insert it into the red-black tree. We
initialize totalweight = and pointer = NIL. Well search in the tree for
where i should go. Everytime we follow a left child, we do nothing. Everytime we
follow a right child of some parent x, we set totalweight = max(totalweight, W [x])
and pointer = P [x]if W [x] > totalweight. So, we essentially keep track of the
maximum weight and the pointer to the node that had it for all keys that are less
than i. When we find where to insert x, we set the weight of the subsequence
ending in x to be ws [x] = totalweight + weight[x]. We also set W [x] = ws [x] and
P [x] = x. In addition, in our original array, we add a pointer from x to pointer,
telling us how to backtrack to find the heaviest increasing subsequence.
We do this for all elements in the sequence (starting with the dummy element
with weight 0). Each insert into the tree takes time lg n and we have to
perform n of them. At the end, we search through the tree for the highest weight
((n)) and follow the pointers back from that element to find the actual heaviest
increasing sequence (O(n)). So, the total running time is (n lg n).
(b) [8 points] Let X = x1 , . . . , xm and Y = y1 , . . . , yn be two sequences. Assume
that the number of pairs (xi , yj ) that match (i.e. xi = yj ) is small, i.e. (k) for
some k(m, n). Assume the set of matching pairs is given to you as part of the
input. Give an O(k lg k) algorithm for finding the longest common subsequence
of X and Y under these conditions.
Hint: reduce this to another sparse DP problem we have seen.
Answer: We will try to reduce our problem to the longest increasing subsequence
problem. Notice that if we try to read through the entire input arrays, we will
take time (n + m) which could be bigger than k, so we are restricted to simply
looking through the pairs of elements given. The longest common subsequence of
X and Y must have increasing indexes in both X and Y . Thus, if we sort the
pairs according to their index in X and feed the corresponding Y indexes into the
longest increasing subsequence algorithm, we will obtain a common subsequence
that is nondecreasing in the X index and increasing in the Y index. To avoid
the problem of potentially having several pairs (xi , yj ) and (xi , yj 0 ) chosen by the
LIS algorithm, we place the pairs with equal values of xi in decreasing order of
yj , so that two pairs with the same X index can never be returned as part of
a subsequence with increasing Y index. Sorting can be done using mergesort in
(k lg k) time, and the sparse version of LIS runs in (k lg k) time, so the overall
running time is (k lg k).
CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #5 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.

1. [25 points] Coin Changing


Consider a currency system with k 1 distinct (integer) denominations d1 < . . . < dk .
Assume that d1 = 1 so that any integer amount greater than 0 can be formed.
Throughout the problem, assume there are always coins of every denomination available
when needed (i.e. you cannot run out of any denomination). Our goal will be to
determine how to make change using the fewest number of coins.
Some parts of this problem are similar to problem 16-1 on page 402 of CLRS. You may
wish to read the statement of that problem to see how similar questions are presented.

(a) [2 points] Describe a greedy strategy for making change using as few coins
as possible. This strategy should work for the US coin system which uses
denominations {1, 5, 10, 25}. You do not need to prove the correctness of this
strategy for this set of denominations.
Answer: The greedy strategy consists of always taking the largest denomination
that we can at the time. We repeat this until we have the correct amount of
change.
MAKE-CHANGE(M)
1 for i = k downto 1
2 count[i] bM/di c
3 M M count[i] di
Since for each denomination we calculate the number of coins we can take until
we would make more than the amount of change asked for, this operation takes
time O(k).
We can also write this in a slightly less efficient manner that will be useful when
analyzing the correctness of the greedy strategy. In this case, we simply take one
coin at a time of the largest denomination possible.
MAKE-CHANGE-SLOW(M)
1 for i = k downto 1
2 while M di
3 count[i] count[i] + 1
4 M M di
This runs in time O(C + k) where C is the number of coins in the greedy solution.
Problem Set #5 Solutions 2

(b) [5 points] Suppose that di = ci1 for some integer c > 1, i.e. the denominations
are 1, c, c2 , . . . , ck1 . Prove that the greedy strategy from part (a) is optimal.
Answer: Well represent a change solution by a series Pof counts, one for each coin
denomination. The counts must obey the property ki=1 count[i] di = M. The
P
number of coins in this solution is ki=1 count[i]. Note that the counts for each
coin denomination di < dk must be strictly less than c in an optimal solution.
Otherwise, if we have count[i] c, we can replace c of the di = ci1 coins which
have value c ci1 = ci with one di+1 = ci coin and get a smaller count.
We will prove by contradiction that the greedy solution is optimal. Let the optimal
count values be represented by optimal[i]. Let j be the first index (highest)
for which count[j] 6= optimal[j]. We know that count[j] > optimal[j] because
the greedy solution always takes the maximum number of any coin and this is
the first value on which they disagree. If the optimal solution Pj1chose more of
coin dj , then it would have made too much change. Let B = i=1 count[i] di ,
the amount of change that the greedy solution makes with the coins 1 . . . j 1.
Since the optimal solution used fewer coins of denomination dj , we know that
the amount of change that the optimal solution makes with coins 1 . . . j 1 is
D = B + (count[j] optimal[j]) dj = B + (count[j] optimal[j]) cj1 . Since
this value is greater than cj1 , we will show that the optimal solution must take
at least c coins for some coin d1 . . . dj1.
Assume that the optimal solution has optimal[i] < c for i = 1 . . . j 1. Then, the
amount of change that the optimal solution makes with the first j 1 coins is
X
j1
D = optimal[i] di
i=1
X
j1
(c 1) ci1
i=1
X
j1
= (c 1) ci1
i=1
X
j2
= (c 1) ci
i=0
j1
c 1
= (c 1)
c1
= cj1 1

However, this contradicts the fact that D was greater than cj1 . Thus, the optimal
solution must take at least c coins for some denomination less than dj . But, as
we showed above, this solution cant be optimal. This is a contradiction and
therefore the greedy solution must take the same number of coins for all coins as
the optimal solution, and thus must itself be optimal.
(c) [2 points] Give a set of coin denominations for which the greedy algorithm will
Problem Set #5 Solutions 3

not always yield the optimal solution. Your set should include d1 = 1 so that
every positive integer amount can be formed.
Answer: A simple example is the set of US denominations without the nickel. If
you simply have the values {1, 10, 25}, the greedy solution will fail. For example,
if you are trying to make change for 30 cents, the greedy solution will first take a
quarter, followed by 5 pennies, a total of six coins. However, the optimal solution
actually consists of three dimes.
(d) [5 points] Suppose you wish to make change for the amount M using an arbitrary
set of denominations (although we still make the assumption that di are distinct
integers and d1 = 1). Give an O(Mk) time algorithm to calculate the minimum
number of coins needed. State the (asymptotic) space usage of your algorithm in
terms of the relevant parameters.
Answer: We can solve this problem using dynamic programming. Notice that
for any value M, we can calculate the optimal solution by looking back at the
number of coins needed to make M di coins for all i and choosing the smallest
number. We fill an array T which ranges from 1 . . . M. At each point in the array,
we store the optimal number of coins needed to make change. We initialize the
cell T [0] with the value 0. Then, for every other cell up to T [M] we calculate

T [i] = 1 + min T [i dj ]
1jk

where we assume that for x < 0, T [x] = . We fill in the table up till T [M] and
then simply look in that cell for the optimal number of coins. Since we have to fill
in M values in the table and each value looks back at k different cells and takes
the minimum, the running time of this algorithm is O(Mk). At any time, we can
look back until the i dk cell, so the space usage is O(min(dk , M)).
(e) [5 points] Suppose Eugene owes Nina an amount M. Give an O(Mkdk ) time
algorithm to determine the minimum number of coins that need to exchange hands
in order to settle the debt (Nina can give change). Assume that neither Eugene
nor Nina will run out of any denomination. State the (asymptotic) space usage
of your algorithm in terms of the relevant parameters.
Answer: We can define an upper bound on the amount of money that Eugene
gives Nina that can be part of an optimal solution. Lets say that Eugene gives
Nina an amount more than Mdk and Nina gives change. Eugene gives at least M
coins, and Nina still gives back coins. But, we know that Eugene could simply
have given Nina M coins of denomination d1 = 1 to make a total value of M
without Nina having to give any change. So, we know that Eugene giving an
amount more than Mdk cant be an optimal solution.
We can therefore use our solution from part (d) to find the optimal ways of giving
change for all values 1 . . . Mdk . Then, for each value i that Eugene can give in
the range M . . . Mdk , Nina will need to give i M change. We simply sum the
number of coins that Eugene gives plus the number of coins that Nina gives:
T [i] + T [i M]. The minimum over all i is the optimal way to settle the debt.
Problem Set #5 Solutions 4

To find the optimal ways to make change for all values up till Mdk takes time
O(Mkdk ) using the algorithm in part (d). Notice that in the process of computing
the optimum for Mdk the algorithm finds the optimal ways to make change for
all the values 1 . . . Mdk so we only need to run it once. Summing and taking the
minimum will take time O(Mdk ), so the running time is bounded by the dynamic
programming part. The algorithm will need to store the previous dk solutions for
the dynamic programming and the previous M solutions for the summation of
T [i] + T [i M]. So, the space usage of the algorithm is O(dk + M).
(f) [6 points] Consider again the greedy algorithm stated in part (a) of the problem.
We want to decide, in a given currency system d1 < . . . < dk , whether the greedy
algorithm is optimal. Give a dynamic programming algorithm to determine the
smallest amount M for which the greedy algorithm fails to produce the optimal
solution. If the greedy approach is always optimal your algorithm should detect
and report this. State the (asymptotic) running time and space usage of your
algorithm in terms of the relevant parameters. You may assume that k 2 so
that the greedy algorithm is not trivial.
Hint: Can you find an upper bound B such that if greedy is optimal for all
M B, then greedy must be optimal for all M?
Answer: We claim that if a counterexample to greedys optimality exists, it must
exist for some M < dk +dk1 . The main idea is that for such M, the greedy choice
is to choose dk , but we will show that doing so either yields an optimal solution
or a smaller counterexample to greedys optimality.
Thus, suppose (for a contradiction) that M dk + dk1 is the smallest amount
such that greedy is not optimal for this amount. This means that OP T [M] >
OP T [M dk ] + 1. However, there must be some denomination dj 6= dk such
that OP T [M] = OP T [M dj ] + 1 (recall how we computed OP T [i] in part
(d)). By assumption, greedy must be optimal for this amount, otherwise we
have a smaller counterexample. However, since dj dk1 (since j 6= k), this
means the optimal greedy choice for M dj dk is in fact dk ; therefore,
OP T [M dj ] = OP T [M dj dk ] + 1. Thus,

OP T [M] = OP T [M dj dk ] + 2

However, notice that we can go from M dk dj to M dk using only the coin


dj ; therefore, OP T [M dk ] OP T [M dk dj ] + 1. Combining this with the
first inequality we established yields

OP T [M] > OP T [M dk dj ] + 2

for the desired contradiction.


Thus, we simply need to compute the optimal solutions for M = 1 . . . dk1 + dk ,
using the algorithm from part (d). As we compute optimum, we must check that
greedy is still optimal by checking whether OP T [M] = OP T [M dj ] + 1, where
dj is the largest denomination M. If we fail to find a counterexample before
M = dk + dk1 , we may stop and report that greedy is always optimal.
Problem Set #5 Solutions 5

The space requirement O(dk ) and the running time of O(kdk ) are obtained by
letting M = O(dk ) in the results from part (d).

2. [16 points] Amortized Weight-Balanced Trees


Throughout this problem, your explanations should be as complete as possible, but
they do not need to be formal. In particular, rather than proving tree properties by
induction you may simply argue why they should hold.

(a) [3 points] Do problem 17-3(a) on page 427 of CLRS.


Answer: We first perform an in-order walk starting from x and store the sorted
output in an array. This will require space (size[x]). Then, to rebuild the
subtree rooted at x, we start by taking the median of the array which we
can find in constant time (by calculating its address in the array) and put it
at the root of the subtree. This guarantees that the root of the subtree is
1/2-balanced. We recursively repeat this for the two halves of the array to
rebuild the subtrees. The total time for the algorithm follows the recurrence
T (size[x]) = 2T (size[x]/2) + 1 = (size[x]).
(b) [2 points] Do problem 17-3(b) on page 427 of CLRS.
Answer: If we perform a search in an n-node -balanced binary search tree, the
worst case split at any point in a subtree with i nodes is recursing to a subtree
with i nodes since we know that the number of nodes in any subtree is bounded
by this value. So, the recurrence is T [n] = T [n] + 1 = (log1/ n), which since
is a constant is simply (log n).
(c) [3 points] Do problem 17-3(c) on page 427 of CLRS.
Answer: If we define the potential of the tree as
X
(T ) = c (x)
xT :(x)2

where (x) = |size[lef t[x]] size[right[x]]|, then the potential for any BST is
non-negative. This is easy to see as every term in the summation is the absolute
value of the difference in the subtree sizes and therefore is non-negative. Also, we
assume that the constant c is positive, thus giving a positive potential (T ).
For a 1/2-balanced BST, we know that size[lef t[x]] (1/2)size[x] and
size[right[x]] (1/2)size[x] for all nodes x in the tree. We will prove by
contradiction that (x) < 2 for all x in the tree. Assume that (x) 2. Then,
|size[lef t[x]] size[right[x]]| 2. Without loss of generality, assume that the
left subtree is larger, so we can drop the absolute value signs. We also know that
the sum of the sizes of the left subtree and the right subtree must be size[x] 1.
Substituting this in for size[right[x]], we find
size[lef t[x]] size[right[x]] 2
size[lef t[x]] (size[x] size[lef t[x]] 1) 2
2 size[lef t[x]] 1 + size[x]
size[lef t[x]] 1/2 + (1/2)size[x]
Problem Set #5 Solutions 6

But, we know from the -balanced condition that size[lef t[x]] (1/2)size[x],
which is a contradiction. Therefore, for all nodes x, (x) < 2. The summation
in the potential equation is only over nodes with (x) 2. Since no such nodes
exist, the summation is 0, and thus (T ) = 0 for a 1/2-balanced tree.
(d) [4 points] Do problem 17-3(d) on page 427 of CLRS.
Answer: We need to pick the constant c such that at any time that we need to
rebuild a subtree of size m, we have that the potential (T ) is at least m. This
is because the amortized cost of rebuilding the subtree is equal to the actual cost
plus the difference in potential. If we want a constant amortized cost, we need
crebuild = crebuild + i i1
O(1) = m + i i1
i1 m
since we know that the end potential i is always greater than zero.
We need to figure out the minimum possible potential in the tree that would
cause us to rebuild a subtree of size m rooted at x. x must not be -balanced, or
we wouldnt need to rebuild the subtree. Say the left subtree is larger. Then, to
violate the -balanced criteria, we must have size[lef t[x]] > m. Since the size of
the subtrees must equal m1, we know that size[right[x]] = m1size[lef t[x]] <
m 1 m = (1 )m 1.
We have
(x) = size[lef t[x]] size[right[x]]
> m ((1 )m 1)
= (2 1)m + 1
We can then bound the total tree potential (T ) > c((2 1)m + 1). We need
the potential larger than m to pay the cost of rebuilding the subtree, so
m c((2 1)m + 1)
m
c
(2 1)m + 1
1
=
2 1 + 1/m
1

2

Therefore, if we pick c larger than this constant based on , we can rebuild the
subtree of size m in amortized cost O(1).
(e) [4 points] Do problem 17-3(e) on page 427 of CLRS.
Answer: The amortized cost of the insert or delete operation in an n-node -
balanced tree is the actual cost plus the difference in potential between the two
states. From part (b), we showed that search took time O(lg n) in an -balanced
tree, so the actual time to insert or delete will be O(lg n). When we insert or
Problem Set #5 Solutions 7

delete a node x, we can only change the (i) for nodes i that are on the path
from the node x to the root. All other (i) will remain the same since we dont
change their subtree sizes. At worst, we will increase each of the (i) for i in the
path by 1 since we may add the node x to the larger subtree in every case. Again,
as we showed in part (b), therePare O(lg n) such nodes. The potential (T ) can
therefore increase by at most c ipath 1 = O(c lg n) = O(lg n). So, the amortized
cost for insertion and deletion is O(lg n) + O(lg n) = O(lg n).

3. [10 points] Off-Line Minimum


Throughout this problem, your explanations should be as complete as possible, but
they do not need to be formal. In particular, when asked to prove the correctness of
the algorithm given in the problem, you do not need to use loop invariants; you may
simply argue why a certain property should hold.

(a) [1 point] Do problem 21-1(a) on page 519 of CLRS.


Answer: For the sequence 4, 8, E, 3, E, 9, 2, 6, E, E, E, 1, 7, E, 5 the extracted
array will hold 4, 3, 2, 6, 8, 1.
(b) [5 points] Do problem 21-1(b) on page 519 of CLRS.
Answer: We will show that the extracted array is correct by contradiction.
Assume that the extracted array is not correct. Let x = extracted[j] be the
smallest value extracted[j] for which the extracted array is incorrect. Let the
correct solution reside in the array correct. Call y the value of correct[j]. We
have two cases, one where x > y and one where x < y. We will prove that neither
case can occur.
Assume that x > y. Then the element y cant appear in the extracted array, or it
would have been the smallest value for which the extracted array was incorrect.
Since weve already processed y before processing x, it must have had a set value
of m + 1. But, if correct[j] was set to y, then y must initially have been in some
Ki with i j. Since extracted[j] had no value yet when we processed y, then we
couldnt have put y in set Km+1 since we only union with the set above us and
we havent unioned Kj yet. Therefore, we cant have x > y.
Assume that x < y. We argue that the element x must appear in the correct array.
Obviously x must appear before the jth extraction in the original sequence since
the OFF-LINE-MINIMUM algorithm never moves sets of elements backwards, it
only unions with sets later than it. If we hadnt extracted x by the jth extraction,
then the optimal solutions should have chosen x instead of y for the jth extraction
since x is smaller. Therefore, the optimal solution must have extracted x for some
i < j. But, that means that extracted[i] holds some z > x. By similar reasoning
as above, we couldnt have moved x past set Ki since extracted[i] would have been
empty at the time x was chosen. So, since we only union with sets above us and
Ki hasnt been unioned yet, we cant put x in extracted[j] before extracted[i].
Therefore, we cant have x < y.
Since we have shown that we must have extracted[j] = correct[j] for all j, the
OFF-LINE-MINIMUM algorithm returns the correct array.
Problem Set #5 Solutions 8

(c) [4 points] Do problem 21-1(c) on page 519 of CLRS.


Answer: We can efficiently implement OFF-LINE-MINIMUM using a disjoint-
set forest. We begin by creating n sets, one for each number, using the MAKE-
SET operation. Then, we call UNION n m times to create the Kj sets, the
sequences of insertions between extractions. For each set Kj , we will also maintain
3 additional pieces of information, number, prev, and next in the representative
element of the set (actually this information will be at all the elements, but it
will only be maintained for the representative). number will correspond to j
and can easily be set with the initial creating of the sets. prev will point to the
representative element of Kj1 and next will point to the representative element
of Kj+1. We can maintain these three properties through unions as follows: when
we union two sets j and l where l is the next set that still exists after j, we set
number of the new representative equal to the maximum of the two representative
numbers, in this case, l. We set prev of the new set equal to prev of set j and we
set next of prev of j equal to the new representative element. Similarly, we set
next of the new set equal to next of set l and we set prev of next of l equal to
the new representative element.
In the OFF-LINE-MINIMUM algorithm, each iteration of the for loop (n
iterations) will first call FIND-SET on i (line 2). We use the number field of
the returned representative as j. Then, in line 5, to determine the smallest l
greater than j for which set Kl exists, we can simply follow the next pointer
from j, which takes constant time. In line 6, we call UNION again, at most m
times throughout the n iterations. For each UNION call, we follow the procedure
above for updating the number, prev and next, all of which take constant time.
Therefore, we have a total of n MAKE-SET operations, n FIND-SET operations,
and n UNION operations. Since we have 3n total operations and n MAKE-
SET operations, we know by Theorem 21.13 that the worst-case running time is
O(3n(n)) = O(n(n)).

4. [23 points] Articulation Points and Bridges


Throughout this problem, your explanations should be as complete as possible. You
do not need to formally prove the correctness of any algorithm you are asked to give;
however, when asked to prove some property of articulation points or bridges, your
argument should be as formal as possible.
Notice that only parts (a)-(f) of problem 22-2 are assigned. Thus, do not worry about
biconnected components for this problem.
If you are looking for the definition of a simple cycle, check appendix B.4.

(a) [3 points] Do problem 22-2(a) on page 558 of CLRS.


Answer: First we will prove the forward direction: If the root of G is an
articulation point, then it has at least 2 children in G . We will prove the
contrapositive, the if the root has less than 2 children in G , then it is not an
articulation point. If r is the root and has no children, then it has no edges
adjacent to it. Thus removing r from G cant disconnect the graph and r is not
Problem Set #5 Solutions 9

an articulation point. If r has one child, then all other nodes in G are reachable
through the child. Therefore, removing r from G will not disconnect G and r is
not an articulation point.
For the reverse direction, we need to show that if the root has at least 2 children
in G then the root is an articulation point. We will prove this by contradiction.
Suppose the root has the two children C1 and C2 and that C1 was explored first in
the DFS. If the root is not an articulation point, then there exists a path between
a node in C1 and one in C2 that does not include the root r. But, while exploring
C1 , we should have explored this path and thus the nodes of C2 should be children
of some node of C1 . But, since they are in a separate subtree of the root, we know
that no path can exist between them and thus r is an articulation point.
(b) [4 points] Do problem 22-2(b) on page 558 of CLRS.
Answer: First we will prove the forward direction. Assume that v is an
articulation point of G. Let Cr be the connected component of G v containing
the root of the tree G . Let s be a neighbor of v that is not in Cr (this neighbor
must exist since removing v must create at least two connected components) and
Cs be the connected component containing s. In G , all the proper ancestors of
v are in Cr , and all the descendants of s are in Cs . Thus, there can be no edges
between descendants of s and proper ancestors of v.
To prove the backward direction, if such a vertex s exists and there is no back
edge from s or any of its descendants to a proper ancestor of v, then, we know
that the only path from the root of the tree to s goes through v. Therefore, if we
remove v from the graph, we have no path from the root of the tree G to s, and
we have disconnected the graph. Thus, v is an articulation point.
(c) [4 points] Do problem 22-2(c) on page 559 of CLRS.
Answer: We can compute low[v] for all vertices v by starting at the leaves of the
tree G . We compute low[v] as follows:

low[v] = min(d[v], min low[y], min d[w])


ychildren(v) backedge(v,w)

For leaves v, there are no descendants u of v, so this returns either d[v] or d[w] is
there is a back edge (v, w). For vertices v in the tree, if low[v] = d[w], then either
there is a back edge (v, w), or there is a back edge (u, w) for some descendant u.
The last term in the min expression handles the case where (v, w) is a back edge.
If u is a descendant of v in G , we know that d[u] > d[v] since u is visited after v
in the depth first search. Therefore, if d[w] < d[v], we also have d[w] < d[u], so
we will have set low[u] = d[w]. The middle term in the min expression therefore
handles the case where (u, w) is a back edge for some descendant u. Since we start
at the leaves of the tree and work our way up, we will have computed everything
we need when computing low[v].
For each node v, we look at d[v] and something related to all the edges leading
from v, either tree edges leading to the children or back edges. So, the total
running time is linear in the number of edges in G, O(E).
Problem Set #5 Solutions 10

(d) [4 points] Do problem 22-2(d) on page 559 of CLRS.


Answer: To compute the articulation points of G, we first run the depth first
search and the algorithm from part (c). Depth first search runs in time O(V + E)
and since the graph is connected, we know E > |V | 1 so this is simply O(E).
We also showed that the algorithm from (c) runs in time O(E). Thus, we have
calculated low[v] for all v V . By part (a), we can test whether the root is
an articulation point in O(1) time. By part (b), any non-root vertex v is an
articulation point if and only if it has a child s in G with no back edge to a
proper ancestor of v. If low[s] > d[v], then there must be a back edge to a proper
ancestor of v. Otherwise, if there is an edge between a node u that is not a proper
ancestor of v and s, and u was visited before v, then we should have explored s
before visiting v.
So, if v has a child s in G such that low[s] d[v], then s has no back edge to a
proper ancestor of v and thus v is an articulation point. We can check this in time
proportional to the number of children of v in G , so over all non-root vertices,
this takes O(V ) time. Thus, the total time to find all the articulation points is
O(E).
(e) [4 points] Do problem 22-2(e) on page 559 of CLRS.
Answer: We will first prove the forward direction: if an edge (u, v) is a bridge
then it can not lie on a simple cycle. We will prove this by proving the
contrapositive, if (u, v) is on a simple cycle, then it is not a bridge. We know that
if (u, v) is a simple cycle, then there is a cycle u v x1 x2 xn u,
such that all of u, v, xi are distinct. If we remove the edge (u, v), then any path
which used to exist in the graph G also exists in G0 . We can prove this because
any path which didnt include the edge (u, v) obviously still exists. Any path
which did include the edge (u, v) can be modified to eliminate the edge u v
and include the path u xn x1 v and similarly for the edge v u.
Thus, (u, v) is not a bridge. So, if (u, v) is a bridge, then it is not on a simple
cycle.
We will now prove the reverse direction and show that if an edge (u, v) is not on
a simple cycle, then it is a bridge. We will prove this by contradiction. Assume
(u, v) is not on a simply cycle but it is not a bridge. Lets say that we remove
the edge (u, v). Since (u, v) is not a bridge, there is still a path connecting u and
v, u x1 x2 xn v. Then, the edges v u x1 xn v form
a simple cycle. But, we assumed that (u, v) wasnt on a simple cycle. So, (u, v)
must be a bridge.
(f) [4 points] Do problem 22-2(f) on page 559 of CLRS.
Answer: Any bridge in the graph G must exist in the graph G . Otherwise,
assume that (u, v) is a bridge and that we explore u first. Since removing (u, v)
disconnects G, the only way to explore v is through the edge (u, v). So, we only
need to consider the edges in G as bridges. If there are no simple cycles in the
graph that contain the edge (u, v) and we explore u first, then we know that there
are no back edges between v and anything else. Also, we know that anything
Problem Set #5 Solutions 11

in the subtree of v can only have back edges to other nodes in the subtree of
v. Therefore, we will have low[v] = d[v] since v is the first node visited in the
subtree rooted at v. Thus, we can look over all the edges of G and see whether
low[v] = d[v]. If so, then we will output that (parent[v]G , v) is a bridge, i.e. that
v and its parent in G form a bridge. Computing low[v] for all vertices v takes
time O(E) as we showed in part (c). Looping over all the edges takes time O(V )
since there are |V | 1 edges in G . Thus the total time to calculate the bridges
in G is O(E).

5. [18 points] Assorted Graph Problems


Throughout this problem, your explanations should be as complete as possible, but
they do not need to be formal. In particular, when asked to prove the correctness of
the algorithm given in the problem, you do not need to use loop invariants; you may
simply argue why a certain property should hold.

(a) [5 points] Do problem 22.1-5 on page 530 of CLRS.


Answer: The edge (u, w) exists in the square of a graph G if there exists a vertex
v such that the edges (u, v) and (v, w) exist in G. To calculate this efficiently from
an adjacency matrix, we notice that this condition
P is exactly what we get when
we square the matrix. The cell M 2 [u, w] = v M[u, v] M[v, w] when we multiply
two matrices. So, if we represent edges present in G with ones and all other entries
as zeroes, we will get the square of the matrix with zeroes when edges arent in
the graph G2 and positive integers representing the number of paths of length
exactly two for edges that are in G2 . Using Strassens algorithm or other more
sophisticated matrix multiplication algorithms, we can compute this in O(V 2.376 ).
Using adjacency lists, we need to loop over all edges in the graph G. For each
edge (u, v), we will look at the adjacency list of v for all edges (v, w) and add the
edge (u, w) to the adjacency lists for G2 . The maximum number of edges in the
adjacency list for v is V , so the total running time is O(V E). This assumes that
we can add and resolve conflicts when inserting into the adjacency lists for G2 in
constant time. We can do this by having hash tables for each vertex instead of
linked lists.
(b) [4 points] Use your result from part (a) to give an algorithm for computing Gk
for some integer k 1. Try to make your algorithm as efficient as possible.
For which k is it asymptotically better to convert G from one representation to
another prior to computing Gk ?
Answer: To calculate the Gk graph using the adjacency matrix representation,
we can use the trick of repeated squaring. Thus, by first calculating Gk/2 for even
k, and G(k1)/2 for odd k, we can solve the problem in time O(V 2.376 lg k). For
adjacency lists, we can do the same thing. If we calculate the G2 graph, we can
calculate the G4 graph by running our algorithm from part (a) on the G2 graph.
Thus, to calculate Gk using adjacency lists takes time O(V E lg k). Converting
between the two representations takes time O(V 2 ) which is asymptotically less
than calculating G2 in either case. Converting between the two represenations
Problem Set #5 Solutions 12

therefore depends on how many edges you have relative to the number of vertices.
If E = o(V 1.376 ) then you should convert to the adjacency list representation and
otherwise you should convert to the matrix. Notice that the number of edges
will keep changing for each Gi so you may need to convert back and forth when
calculating Gk .
(c) [4 points] Do problem 22.3-11 on page 549 of CLRS. How does your algorithm
compare (in the asymptotic running time sense) with the algorithm given in class
and in section 21.1 of CLRS for determining the connected components of G using
disjoint-set data structures?
Answer: We will first modify DFS to label the connected components.
DFS(G)
1 for each vertex u V [G]
2 do color[u] WHITE
3 [u] NIL
4 time 0
5 k0
6 for each vertex u V [G]
7 do if color[u] = WHITE
8 k k+1
9 DFS-VISIT(u, k)
Lines 5, 8, and 9 are the ones which were added or changed. In DFS-VISIT, we
will always call DFS-VISIT with the same value of k. In addition, after setting
the color of u to BLACK, we will set the connected component, cc[u] to k.
Since the graph G is undirected, two nodes u and v will only get the same
connected component label if there is a path between them in the graph G.
The running time of this algorithm is the same as for DFS which is O(V + E).
The algorithm given in section 21.1 of CLRS runs in time O((V + E)(V )), which
is asymptotically slower. However, (V ) is very small ( 4) for any reasonable
size V , so the running times are comparable.
(d) [5 points] Do problem 22.4-2 on page 552 of CLRS.
Answer: We first run topological sort on the graph G. This takes time O(V +E).
We know that any path that runs between s and t must use only the vertices
located between s and t in the topological sort. If there was a vertex a < s in the
topological sort, then there cant be a path from s a in G. Likewise there can
be no vertex b > t on a path from s to t. So, we can ignore all vertices < s or
> t in the topological sort. Then, we can use dynamic programming to calculate
the number of paths from s to t. We will label each node from s to t with the
number of paths from s to that node. We start by labelling the node s with a 1
since there is one path from s to s and by labelling all other nodes with 0. Then,
for each node i starting from s in the sort, we calculate the number of paths from
s as
Problem Set #5 Solutions 13

X
paths[i] = paths[j]
(j,i)E

We finish when we calculate paths[t] which we output as the answer. This


algorithm is correct since all paths from s to i must only contain vertices between
s and i in the topological sort. These we have calculated by the time we calculate
paths[i]. Also, the predecessor to i on any path from s to i must be such that
there is an edge from (pred, i). We sum over all possible predecessors to calculate
paths[i]. For at most each vertex, we sum over the number of incoming edges.
So, in total, we look at each edge once. Therefore, the running time of this step
is O(V + E). Thus, the total time for this algorithm is O(V + E) which is linear
in the size of the input.

6. [18 points] Minimal Spanning Trees


Throughout this problem, if you are arguing about the correctness of a minimal
spanning tree algorithm, please be as formal as possible in proving the property the
algorithm relies on for its correctness; however, you do not need to resort to loop
invariants or similar formal methods to prove the correctness of the actual algorithm.

(a) [6 points] Do problem 23.1-11 on page 567 of CLRS.


Answer: If we decrease the weight of an edge (u, v) not in T , then the new
minimal spanning tree may now contain that edge. The algorithm to compute
the new minimum spanning tree is to find the heaviest weight edge on the path
from u v. If this edge weight is higher than the weight of edge (u, v), then we
delete this edge and add (u, v). Else, we do nothing. The running time of this
algorithm is the time taken to find the heaviest weight edge on the path u v.
We can do this by running DFS from from u till we hit v since there is only one
path from u to v in a tree. The running time is O(V + E) = O(V ) since this is a
tree. The result is obviously a spanning tree. We will show that it is a minimum
spanning tree.
We will do this by considering Kruskals algorithm over the new graph. Kruskals
algorithm grows an MST by always adding the lowest weight edge that does not
create a cycle. For all edges in the MST with weight less than w 0 (u, v), we will
take the exact same edges as we did before. When we consider the edge (u, v),
we have two choices, either we take the edge or we dont. If we dont take the
edge, then (u, v) must have created a cycle in the MST. All edges in the cycle
must have weight less than w 0 (u, v) or they wouldnt be in the MST already. The
algorithm will then proceed as before. This corresponds to the above case where
we dont modify the MST. If we take the edge (u, v) then all further edges will be
added in the same manner until we reach the one which creates a cycle with the
edge (u, v). This will be the highest weight edge in the original path from u v,
which we wont add. All other edges will be added as before. This corresponds
to the case where our algorithm deletes the highest weight edge on the path from
Problem Set #5 Solutions 14

u v and adds the edge (u, v). Our algorithm produces the same spanning tree
that Kruskals algorithm produces, and it is therefore a minimum spanning tree.
(b) [6 points] Do problem 23.2-7 on page 574 of CLRS.
Answer: Lets assume that we add the new vertex and incident edges and
initialize all the edge weights to . Then, we can take any of the edges and
add it to the original spanning tree to give a minimum spanning tree. Using the
answer from part (a), we know that we can reduce the weight of this edge and
the other edges one at a time, add the edge to the MST, and remove the edge
with the highest weight in the newly created cycle. This will run in time O(V 2 )
since there may be at most V edges from the new vertex. However, we can do
better by noticing that the only possible edges in the new MST are the ones in
the old MST or the new edges we just added. There are a total of |V | 1 edges
in the old MST and a total of at most |V | edges added. So, if we simply run
either Kruskals or Prims algorithm on the graph with all the vertices but only
these |E| = 2|V | 1 = O(V ) possible edges, we will create the new MST in time
O(V lg V ), which is better than the O(V 2 ) time.
(c) [6 points] Do problem 23.2-8 on page 574 of CLRS.
Answer: This algorithm does not compute the minimum spanning tree correctly.
Suppose we have a graph with three nodes, A, B, C. Suppose also that the graph
has three edges with the following weights: w(A, B) = 1, w(B, C) = 2, w(C, A) =
3. Lets say we partition the graph into the two sets V1 = {A, C} and V2 = {B}.
This partition satisfies the condition that |V1 | and |V2 | differ by at most 1. The
edges sets will be E1 = {(A, C)i} and E2 = . So, when we recursively solve the
subproblems, we will add the edge (A, C). Then, when we select the minimum
edge that crosses the partition, we will select the edge (A, B) with weight 1. The
total weight of our MST is 1 + 3 = 4. However, the actual minimum spanning
tree has edges (A, B) and (B, C) and weight 1 + 2 = 3. Therefore, this algorithm
fails to produce the correct minimum spanning tree.
CS161: Design and Analysis of Algorithms Summer 2004

Problem Set #6 Solutions


General Notes
Regrade Policy: If you believe an error has been made in the grading of your problem
set, you may resubmit it for a regrade. If the error consists of more than an error in
addition of points, please include with your problem set a detailed explanation of
which problems you think you deserve more points on and why. We reserve the right
to regrade your entire problem set, so your final grade may either increase or decrease.

Throughout this entire problem set, your proofs should be as formal as possible. However,
when asked to state an algorithm, you do not need to give pseudocode or prove correctness
at the level of loop invariants. Your running times should always be given in terms of |V |
and/or |E|. If representation of the graph is not specified, you may assume whichever is
convenient.

1. [19 points] Gabows Scaling Algorithm for Single-Source Shortest Paths

(a) [5 points] Do problem 24-4(a) on page 616 of CLRS.


Answer: Since the edge weights are all positive, we can use Dijkstras algorithm
to find the shortest paths from the start vertex to all other vertices. The running
time of Dijkstras algorithm using a binary heap is O(E lg V ). The lg V term
comes from the V calls to extract-min and the E calls to decrease-key.
Because of the constraints that the edge weights are integers and that the shortest
path distances are bounded by |E|, we can do better. We can use a method similar
to counting sort to maintain the list of vertices. We know that the weights of the
path to each vertex will always be an integer between 0 and |E|, so we can keep an
array SHORTEST of linked lists for each possible value. For Dijkstras algorithm,
we need to implement the INSERT, DECREASE-KEY, and EXTRACT-MIN
functions. INSERT is easy. If we want to insert a vertex that is reachable in
length i, we simply add it to the beginning of the linked list in SHORTEST[i],
which is O(1). To call DECREASE-KEY on a vertex v, we remove v from its
current linked list (O(1)), decrease its key to i, and insert it into SHORTEST[i],
for a total time of O(1). To EXTRACT-MIN, we notice that throughout the
running of Dijkstras algorithm, we always extract vertices with shortest paths of
non-decreasing value. So, if the previous vertex was extracted at value i, we know
that there can be no vertices in the array at values less than i. So, we start at
SHORTEST[i] and if it is non-empty, we remove the first element from the linked
list. If it is empty, we move up to SHORTEST[i + 1] and repeat. The actual
extraction takes time O(1). Notice that the scanning for a non-empty list could
take time O(E) since there are a total of E lists, but since we never backtrack,
Problem Set #6 2

this O(E) scan of the lists is averaged over the O(V ) calls to EXTRACT-MIN,
for an amoritized cost of O(E/V ) each.
Our total running time therefore includes V calls to INSERT (O(V )), E calls
to DECREASE-KEY (O(E)) and V calls to EXTRACT-MIN (O(V + E)) for a
total running time of O(V + E). Since we know |E| > |V | 1, the O(E) term
dominates for a running time of O(E).
(b) [1 point] Do problem 24-4(b) on page 616 of CLRS.
Answer: Using part (a), we can show how to compute 1 (s, v) for all v V in
O(E) time. We know that 1 (s, v) is computed using the edge weight function
w1 , which only uses the first significant bit of the actual edge weights. Therefore,
the weights w1 are always either 0 or 1. The maximum number of edges on a
shortest path is |V | 1 since it can have no cycles. Since the maximum edge
weight w1 is 1, the maximum weight of a shortest path is |V | 1. Therefore, we
have the condition that for all vertices v V , we have 1 (s, v) |V | 1 |E| by
assumption. From part (a), we know that we can compute 1 (s, v) for all v V
in O(E) time.
(c) [3 points] Do problem 24-4(c) on page 616 of CLRS.
Answer: We know that wi is defined as bw(u, v)/2kic. We will show that either
wi (u, v) = 2wi1 (u, v) or wi (u, v) = 2wi1 (u, v) + 1. Weight wi is the i most
significant bits of w. We can get wi from wi1 by shifting wi1 to the left by
one space and adding the ith significant bit. Shifting to the left is equivalent to
multiplying by 2 and the ith significant bit can be either 0 or 1. So, we have that
wi (u, v) = 2wi1 (u, v) if the ith significant bit is a zero or wi (u, v) = 2wi1 (u, v)+1
if the ith significant bit is a one.
We now want to prove that 2i1 (s, v) i (s, v) 2i1 (s, v) + |V | 1. The
shortest path i (s, v) has weight

X
i (s, v) = min wi (e)
eP ath(s,v)
X
min 2wi1 (e)
eP ath(s,v)
X
= 2 min wi1 (e)
eP ath(s,v)

= 2i1 (s, v)

with the inequality holding because the wi (e) is greater than or equal to 2wi1 (e)
since it equals either that or that plus one. The last equality holds because the
minumum weight of any path from s to v using the weight function wi1 is equal
to the shortest path distance from s to v using wi1 .
Similarly,
Problem Set #6 3

X
i (s, v) = min wi (e)
eP ath(s,v)
X
min (2wi1 (e) + 1)
eP ath(s,v)

X X
= min 2 wi1 (e) + 1
eP ath(s,v) eP ath(s,v)

X
min 2 wi1 (e) + |V | 1
eP ath(s,v)

= 2i1 (s, v) + |V | 1

The first inequality holds because wi (e) is less than or equal to 2wi1 (e) + 1 by
similar reasoning as above. We then set the minimum weight of any paths from
s to v using the weight function wi1 equal to the shortest path as above. The
second inequality holds because the minimum path length is bounded by |V | 1
because it can have no cycles.
(d) [3 points] Do problem 24-4(d) on page 616 of CLRS.
Answer: We define for i = 2, 3, . . . k and all (u, v) E,

wi (u, v) = wi (u, v) + 2i1 (s, u) 2i1 (s, v)

We wish to prove for all i = 2, 3, . . . , k and all u, v V that wi of edge (u, v) is a


nonnegative integer. We can prove this starting from the triangle inequality.

i1 (s, v) i1 (s, u) + wi1 (u, v)


2i1 (s, v) 2i1 (s, u) + 2wi1 (u, v)
2i1 (s, v) 2i1 (s, u) + wi (u, v)
0 wi (u, v) + 2i1 (s, u) 2i1 (s, v)
0 wi

Thus, wi is never negative. It is an integer since all the edge weights are always
integers and thus all the shortest path distances are always integers.
(e) [4 points] Do problem 24-4(e) on page 617 of CLRS.
Answer: We define i (s, v) as the shortest path weight from s to v using wi . We
want to prove for i = 2, 3, . . . k and all v V that

i (s, v) = i (s, v) + 2i1 (s, v)


Problem Set #6 4

and that i |E|.


We prove this by expanding the i (s, v) term.

i (s, v) = min
X
wi(e)
eP ath(s,v)

= min(wi(s, x1 ) + wi (x1 , x2 ) + + wi (xn , v))


= min(wi(s, x1 ) + 2i1 (s, s) 2i1 (s, x1 )) +
(wi (x1 , x2 ) + 2i1 (s, x1 ) 2i1 (s, x2 )) + +
(wi (xn , v) + 2i1 (s, xn ) 2i1 (s, v))
X
= min(2i1 (s, s) 2i1 (s, v) + wi (e))
eP ath(s,v)
X
= 2i1 (s, v) + min wi (e)
eP ath(s,v)

= 2i1 (s, v) + i (s, v)


i (s, v) = i (s, v) + 2i1 (s, v)

We expand i (s, v) in terms of the weights of edges along the path. We see that
if we also expand the wi terms, many things cancel. The term i1 (s, s) = 0
since the shortest path from a node to itself is zero regardless of the edge weight
function. Also, we know that the minimum path length from s to v using the wi
function is i (s, v).
From this, we can easily show that i |E| using the results from part (c).

i (s, v) = i (s, v) + 2i1 (s, v)


2i1 (s, v) + |V | 1 i (s, v) + 2i1 (s, v)
i (s, v) 2i1 (s, v) + |V | 1 2i1 (s, v)
i (s, v) |V | 1
i (s, v) |E|

(f) [3 points] Do problem 24-4(f) on page 617 of CLRS.


Answer: If we are given i1 (s, v), we can compute wi (u, v) using the equation
in part (d) in time O(E) since we can easily calculate wi (u, v) and we need to
compute it for each edge. In part (e), we showed that i (s, v) is bounded by |E|.
So, we can use the results from part (a) to compute the shortest path distances
i (s, v) in time O(E). From these results, we can use the equation in part (e) to
calculate the shortest path distances i (s, v) in time O(V ), once for each vertex.
Therefore, we can compute (s, v) in time O(E lg W ). We will simply start by
calculating 1 (s, v) in time O(E) as we showed in part (b). Then, as we just
explained, we can calculate each i+1 from i in time O(E). In total, we need to
calculate up till k . Since k = O(lg W ), the running time of this is O(E lg W ).
Problem Set #6 5

2. [12 points] Transitive Closure of a Dynamic Graph

(a) [3 points] Do problem 25-1(a) on page 641 of CLRS.


Answer: When we add a new edge to a graph, we need to update the transitive
closure. The only new paths we will add are the ones which use the new edge
(u, v). These paths will be of the form a ; u v ; b. We can find all these
new paths by looking in the old transitive closure for the vertices a A which
had paths to u and for vertices b B which v had paths to. The new edges in the
transitive closure will then be (a, b), where a A and b B. Since the number
of vertices in each set A or B is bounded by V , the total number of edges well
need to add is O(V 2 ). If we represent the transitive closure graph G with an
adjacency matrix, we can very easily find the sets A and B. A will be all the
vertices which have a one in the column u and B will be all the vertices which
have a one in the row v.
(b) [1 point] Do problem 25-1(b) on page 641 of CLRS.
Answer: Suppose our graph G consists of two disjoint graphs, each of size V /2.
Assume that each subgraph is complete, that there are edges between each vertex
in the subgraph to all other vertices in the same subgraph. If we then add an edge
from a vertex in the first subgraph to one in the second subgraph, we will need
to add edges in the transitive closure from every vertex in the first subgraph to
every vertex in the second subgraph. This is a total of V /2 V /2 = V 2 /4 edges.
Regardless of what our algorithm is for calculating the transitive closure, we will
always need to add (V 2 ) edges, and thus the running time must be (V 2 ).
(c) [8 points] Do problem 25-1(c) on page 641 of CLRS.
Answer: We will give you an outline of the solution to this problem on the final
exam. You will then complete it and analyze its correctness and running time.

3. [24 points] Assorted Graph Problems

(a) [8 points] Do problem 22.2-7 on page 539 of CLRS. Assume the edges of T
are undirected and weighted, and give your running time in terms of |V | (since
|E| = |V | 1).
Answer: First notice that the shortest path distance between two vertices is
given by the length of the path between the two vertices, since there is only one
path between any pair of vertices in a tree. So, we are basically asking for the
longest simple path between any two leaves in a tree.
We will keep two items of information at each edge (u, v) T . We will keep
d[u v], which represents the longest simple path distance in the tree from u to
v to any leaf. Also, we keep d[v u], defined symmetrically.
First we arbitrarily root the tree at some vertex r by pointing all the edges outward
from r. We will compute the downward distances bottom-up, and then the upward
distance top-down.
Problem Set #6 6

COMPUTE-DOWN(x)
1 if IsLeaf(x)
2 return
3 for y children(x)
4 COMPUTE-DOWN(y)
5 d[x y] w(x, y) + maxzchildren(y) d[y z]
After calling COMPUTE-DOWN on the root of the tree r, every edge will have
its downward field set. Notice that because of the recursion, the information is
actually first computed at the leaves and then propagated upward.
The top-down pass is somewhat tricker, because now we must integrate
information from different branches as we descend down the tree. There are
two differences: first, the information is now computed at the top first, and at
the bottom at the end; second, updating d[y x] where x is the parent of y now
depends not only on d[x p(x)] but also on d[x z], where z are other children
of x. However, these values were computed on the downward pass; therefore, as
long as we compute d[x p(x)] before d[y x], we have all the information we
need.
COMPUTE-UP(x)
1 p parent(x)
2 for y children(x)
3 d[y x] w(x, y) + maxzchildren(x){p},z6=y d[x z]
4 COMPUTE-UP(y)
Thus, to calculate the diameter, we root the tree arbitrarily at a vertex r, call
COMPUTE-DOWN(r) and then COMPUTE-UP(r). The largest value d[u v]
computed during these procedures is indeed the diameter of the tree.
The first procedure clearly runs in O(V ), since every edge u v is examined at
most twice - once when we d[u v], and once when we set d[p(u) u].
The second procedure as it is written runs in worst-case time O(V 2 ), since if we
have a node with (V ) chilren, we will be looking through all the downward
distance values V times for each maximization step in line 3. However, we notice
that the only useful values from that step are the two largest downward x z
values, since at most one such z can be the y we are currently looking at. Thus,
we precompute at each node x the two largest x z values, and then use the
largest unless z = y. Thus, each edge is considered at most a constant number of
times, and the running time is O(V ) as well.
(b) [8 points] Do problem 22-3(b) on page 559 of CLRS. You may assume the result
of 22-3(a) without proof.
Answer: From part (a), we know that if there is an Euler tour in the graph G,
then the in-degree equals the out-degree for every vertex v. Because of this fact,
we know that if we pick a path with unique edges, any time we reach a vertex
(use one of the in-degree edges), there must still be a way to leave the vertex (use
one of the out-degree edges) except for the first vertex in the path.
Our algorithm therefore is to pick a random starting vertex v. We pick an outgoing
Problem Set #6 7

edge from v, (v, u), at random. We move to vertex u and delete edge (v, u) from
the graph and repeat. If we get to a vertex with no outgoing edges and it is not
equal to v, we report that no Euler tour exists. If the vertex with no outgoing
edges is v, we have a cycle, which we represent as v u v.
The problem is that we may not have visited all the edges in the graph yet. This
may only occur if there are vertices in our cycle which have outgoing edges that
we didnt traverse. Otherwise, our graph would not be connected. If we can
efficiently pick one of these vertices u and start a cycle from that point, we know
that the new cycle from u will end at u by the same reasoning as above. Therefore,
we can connect the two cycles {. . . a u b . . . } and {u c d u} by
making one big cycle {. . . a u c d u b . . . }. This is a valid cycle
since we removed all the edges in the first cycle before computing the second cycle,
so we still have the property that each edge is used at most once. We assume
that when we start the new cycle from u, we keep a pointer to the position of u
in the old cycle so that we know where to break the old cycle in constant time.
If we repeat this process until there are no more edges in the graph, we will
have an Euler tour. The only problem is how to pick the vertex u that still has
outgoing edges from the current cycle. Our original vertex was v. For the first
cycle created, we simply walk along the cycle from v and let u equal the first
vertex which still has outgoing edges. Then, after adding the next cycle, we start
walking from u along the newly merged cycles and so on. Once we have traversed
the path from v ; u, we know that none of the vertices in that section can ever
have outgoing edges, so we dont need to consider them the second time. We will
need to walk over the entire Euler tour at some point in the algorithm, so the
total running time of finding the vertex u for all the cycles is O(E). Also, the
cost of actually finding the cycles traverses each edge exactly once, so it is also
O(E). Therefore, the total running time of the algorithm is O(E).
(c) [3 points] Suppose we have a single-source shortest path algorithm A that runs
in time f (|V |, |E|) when all edge weights are nonnegative. Give an algorithm to
solve problem 24.3-4 on page 600 of CLRS in time f (|V |, |E|) + O(E) by using A
as a subroutine.
Answer: The reliability of a path from u to v is the product of the reliabilities
of each edge in the path. This is because the probability that the channel does
not fail is the probability that all individual edges do not fail. Since the failures
or successes of the individual edges are independent, we simply multiply to get
the total probability of success.
But, our shortest path algorithm finds the shortest path by summing the edge
weights. We need some transformation of our reliabilities so that we can use the
shortest path algorithm given. One function we have seen that converts a product
of terms to a sum of terms is the log function.
If we define a new weight function w(u, v) = lg(r(u, v)), then all the edge
weights are positive since the log of a positive number less than 1 is negative. As
the reliability decreases, the value of the weight of the edge will increase. Since
we are trying to find the most reliable path, this will correspond to the shortest
Problem Set #6 8

weight path in the graph with the new edge weights.


We can show this more formally, where RPATH represents the reliability of a
path.

Y
RP AT H(s, t) = r(e)
eP ath(s,t)
X
log RP AT H(s, t) = log r(e)
eP ath(s,t)
X
log RP AT H(s, t) = log r(e)
eP ath(s,t)

Since the log function is monotonic as long as the base is greater than 1, if we
find the minimum path with edge weights w, we will also find the most reliable
path.
The time for the conversion to the weight function w is constant for each edge,
so the total time is O(E). We then call the single-source shortest path algorithm
which runs in time f (|V |, |E|) and returns our most reliable path. Therefore, the
total running time is f (|V |, |E|) + O(E).
(d) [5 points] Do problem 25.2-9 on page 635 of CLRS.
Answer: If we have an algorithm to compute the transitive closure of a directed
acyclic graph, we can use it to calculate the transitive closure of any directed
graph. We first decompose the directed graph G into its strongly connected
component graph GSCC . This runs in time O(V + E) and results in a graph with
at most V vertices and E edges. We keep track of which set of vertices in G
map to each vertex in GSCC . Call this g(v) which returns a stronly connected
component in GSCC . We then call the transitive closure algorithm on the graph
GSCC . This runs in time O(f (|V |, |E|)). All that is left is to convert back from the
strongly connected component graphs transitive closure to Gs transitive closure.
There is an edge (u, v) in the transitive closure of G if and only if there is an edge
(g(u), g(v)) in the graph GSCC . The forward direction is easy to see. If there
is a path from u to v in G, then there must be a path between the component
that u belongs to and the one that v belongs to in GSCC . The reverse direction
is equally easy. If there is a path between us strongly connected component and
vs strongly connected component in GSCC , then there is a path between some
vertex a in g(u) and some vertex b in g(v) in G. But, since u and a are in the
same SCC, there is a path from u ; a and since v and b are in the same SCC,
there is a path from v ; b. Therefore, there is a path u ; a ; b ; v in G.
To actually calculate the transitive closure of G this way would require time V 2
since wed need to look at all pairs. Instead, we will look at the transitive closure
of GSCC . For each edge (a, b) in the transitive closure of GSCC , we assume that
we know the set of vertices in G that map to a and b, call these sets g 1(a) and
g 1 (b) respectively. We will add the edge (x, y) for all vertices x g 1(a) and
Problem Set #6 9

y g 1 (b). This will take time equal to the number of edges in the transitive
closure of G, O(E ).
Therefore the total running time for the algorithm is the time to build the strongly
connected components (O(V +E)), the time to run the transitive closure algorithm
on GSCC (O(f (|V |, |E|)) and the time to convert back to the transitive closure of
G (O(E )). Since we know that E < E , the total time is O(f (|V |, |E|)+V +E ).

You might also like