Docsity

Math 184A - Second Exam Solutions for Week of February 26, 2001, Exams of Mathematics

Toggle sidebar
bg1
Math 184A Second Exam Solutions 26 February 2001
1. (45 pts.) (a) Compute the rank of the permutation 1,5,3,4,2 when the permutations
of {1,2,3,4,5}are listed in direct insertion order.
Ans. If we start numbering positions with 0 and let p(i) be the position where iis
inserted, then the rank is (5!/2!) p(2) + (5!/3!) p(3) + (5!/4!) p(4) + (5!/5!) p(5).
Since p(2) = 0, p(3) = 1, p(4) = 1, and p(5) = 3, the rank is 28. You could also
draw the relevant part of the decision tree here and in (b) and (c) to figure things
out.
(b) What permutation immediately follows 1,5,3,4,2 in direct insertion order?
Ans. Increase p(5) by 1, giving 5,1,3,4,2.
(c) What permutation immediately follows 1,5,3,4,2 in lex order?
Ans. Starting from the right, we look for the first position that can be increased. The
2 can’t be changed since there’s nothing to replace it with. The 4 can only be
replaced by 2, which is a decrease. The 3 can be replaced by 2 or 4. To increase,
use 4. Next arrange the left over 2 and 3 to give the leftmost possibility. We have
1,5,4,2,3.
2. (20 pts.) Find the unlabeled rooted plane tree with 7 leaves and rank 60.
Ans. We have 56 = b1b6+b2b5≤60 <b
1
b
6+b
2
b
5+b
3
b
4
. Also 60 −56 = 0b4+4. Thus
the left subtree of the root has 3 leaves and rank 0 while the right has 4 leaves and
rank 4. Each of these is easy to determine: Rank 0 means keep all the branching
to the right. Rank bk−1 means keep all the branching to the left.
b1=b2=1,b
3
=2,b
4
=5,b
5
=14,b
6
=42,b
7
= 132.
3. (30 pts.) Let Cn(k) be the number of times position kis changed in the Gray code
for n-long vectors of zeroes and ones given in the text. You may use the following fact
without proving it:
Cn(k)=(1ifk=1,
2C
n−1
(k−1) if 1 <k≤n,
0ifk>n.
(a) Tabulate values of Cn(k) for 1 ≤k≤n≤4.
Ans. This is straightforward.
(b) State and prove a simple formula for Cn(k) that does not involve a recursion.
Ans. You can guess from (a) that Cn(k)=2
k−1for 1 ≤k≤nand zero otherwise.
This can proved by induction. Should we induct on nor k? Either will work
However, since the answer does not depend on nand “Cn(k)=1ifk= 1” looks
like an initial condition, it may be somewhat easier to induct on k. (It is.) As
noted, this is the base case. For kin the range 2 ≤k≤n, we have
Cn(k)=2C
n−1
(k−1) by the given formula,
=2×2
k−2by A(k−1),
=2
k−1
.
1
pf2

Partial preview of the text

Download Math 184A - Second Exam Solutions for Week of February 26, 2001 and more Exams Mathematics in PDF only on Docsity!

Math 184A Second Exam Solutions 26 February 2001

  1. (45 pts.) (a) Compute the rank of the permutation 1, 5 , 3 , 4 , 2 when the permutations of { 1 , 2 , 3 , 4 , 5 } are listed in direct insertion order. Ans. If we start numbering positions with 0 and let p(i) be the position where i is inserted, then the rank is (5!/2!) p(2) + (5!/3!) p(3) + (5!/4!) p(4) + (5!/5!) p(5). Since p(2) = 0, p(3) = 1, p(4) = 1, and p(5) = 3, the rank is 28. You could also draw the relevant part of the decision tree here and in (b) and (c) to figure things out. (b) What permutation immediately follows 1, 5 , 3 , 4 , 2 in direct insertion order? Ans. Increase p(5) by 1, giving 5, 1 , 3 , 4 , 2. (c) What permutation immediately follows 1, 5 , 3 , 4 , 2 in lex order? Ans. Starting from the right, we look for the first position that can be increased. The 2 can’t be changed since there’s nothing to replace it with. The 4 can only be replaced by 2, which is a decrease. The 3 can be replaced by 2 or 4. To increase, use 4. Next arrange the left over 2 and 3 to give the leftmost possibility. We have 1 , 5 , 4 , 2 , 3.
  2. (20 pts.) Find the unlabeled rooted plane tree with 7 leaves and rank 60. Ans. We have 56 = b 1 b 6 + b 2 b 5 ≤ 60 < b 1 b 6 + b 2 b 5 + b 3 b 4. Also 60 − 56 = 0b 4 + 4. Thus the left subtree of the root has 3 leaves and rank 0 while the right has 4 leaves and rank 4. Each of these is easy to determine: Rank 0 means keep all the branching to the right. Rank bk − 1 means keep all the branching to the left.

b 1 = b 2 = 1, b 3 = 2, b 4 = 5, b 5 = 14, b 6 = 42, b 7 = 132.

  1. (30 pts.) Let Cn(k) be the number of times position k is changed in the Gray code for n-long vectors of zeroes and ones given in the text. You may use the following fact without proving it:

Cn(k) =

1 if k = 1, 2 Cn− 1 (k − 1) if 1 < k ≤ n, 0 if k > n.

(a) Tabulate values of Cn(k) for 1 ≤ k ≤ n ≤ 4. Ans. This is straightforward. (b) State and prove a simple formula for Cn(k) that does not involve a recursion. Ans. You can guess from (a) that Cn(k) = 2k−^1 for 1 ≤ k ≤ n and zero otherwise. This can proved by induction. Should we induct on n or k? Either will work However, since the answer does not depend on n and “Cn(k) = 1 if k = 1” looks like an initial condition, it may be somewhat easier to induct on k. (It is.) As noted, this is the base case. For k in the range 2 ≤ k ≤ n, we have

Cn(k) = 2Cn− 1 (k − 1) by the given formula, = 2 × 2 k−^2 by A(k − 1), = 2k−^1.

Math 184A Second Exam Solutions 26 February 2001

  1. (30 pts.) Let bn be the number of binary unlabeled rooted plane trees with n leaves. It is known that bn < 4 bn− 1 for n > 1 and you may use this fact without proof. (It can be proved by using Exercise 9.1.12.) (a) Show that, for more than bn/4 of these trees with n leaves, the left subtree consists of just a single leaf when n > 1. In other words, show that if the two edges leading from the root go to trees T 1 and T 2 , then we have |T 1 | = 1 in more than bn/4 of the cases. Hint: What does the term bibn−i in bn = b 1 bn− 1 + b 2 bn− 2 + · · · + bn− 1 b 1 count? Ans. Let |T | be the number of leaves of T Following the hint, bibn−i counts those T with |T | = n, |T 1 | = i and |T 2 | = n − i. Thus the number with |T 1 | = 1 is b 1 bn− 1 = bn− 1 > bn/4, where the inequality follows from Bn < 4 bn− 1.

(b) Find a constant P > 1 /4 such that the following statement is true for n > 1 about those binary trees with n leaves. “In more than P bn of them, the left subtree contains at most 2 leaves.”

Ans. From bN < 4 bN − 1 at N = n and N = n − 1, we have bn < 4 bn− 1 < 42 bn− 2. Thus bn− 2 > bn/16. Reasoning as in (a), the number of such trees is greater than

b 1 bn− 1 + b 2 bn− 2 = bn− 1 + bn− 2 < bn/4 + bn/16 = 4bn/ 16.

Thus P can have any value such that 1/ 4 < P ≤ 5 /16.