CS4050: HW #5
The smallest depth of a leaf in a decision tree corresponds to the least number of comparisons
needed to sort. For sorting n numbers, this depth is n 1. This is so because the input may happen
to be sorted. If this is the case
1) Prove that 2n2 - 4n + 7 = (n2); give the values of the constants and
show your work.
A) We need to show that
c1n2 2n2 - 4n + 7 c2n2
for c1, c2 0 and n n0
Dividing throughout by n2, we get:
c1 2 4/n + 7/n2 c2
for c1, c2 0 and
1) Argue that the solution to the recurrence T (n) = 3T (n/4) + (n2) is O (n2) by
appealing to a recursion tree. Verify your bound by the substitution method.
A) Please refer to your text book. The above question is the first of
I) What is an optimal Huffman code for the following set of frequencies, based on the
first 8 Fibonacci numbers? a.l , b:l, c:2, d:3, e:5, 1":8,g:13, h:21.
J-7' ~-rL -
~w;r Dd ~.
I 2 n 2 - 4 n + 7 = e (rr'):, give the values of the constants and
1) Prove that
show your work.
(i) tJe. v-uJ
Cv ,J;~i'.;N\ -t:~ek
Exercise 4 (15 points). Suppose that you have a black-box worst-case linear-time median subroutine.
Give a simple, linear-time algorithm that solves the s ection problem for an arbitrary order statistic.
ELEC7(A,F, r, i) _
5 = W_mdm, mtmmj
fume MN m
CS4050 /7050: Exam 2
Exercise 1 (36 points). Short answers.
What prb'perty0) m~st a stable sorting algorithm satisfy?
What, value of q does PARTITION ret71l'l1w n all elements i
Exercise 5. (18 points) Solve the following recurrence relations. Show your work and give
your answer in terms of @- tation.
7W: 4Tln/U-tn . '3 [mi/cfw_1&5 Wear- W A 1.0 ,3
0 T(n) =4T(n/3) +n 71w?" . 'Iu-n : 0615;]ng d I . 0
d [44) M WV 9am) Tun; J21 5534
CS4050/7050: Exam 2
1 (20 points). Show that the running time of QUICKSORT is
when the array A contains
distinct elements and is sorted in decreasing order. For full credit, you need to provide an accurate description
of how QUICKS
3 (20 points), Show the content of the array (9,1,5,6,3,2,8,7,5,4,5)
pass of the PARTITION function of QUICKSORT,
7s 6 ~
q s: 6 ? 2- l? 7
~ "c ~ q .l- .fl
.> Cf S
CS4050: HW #10
Assume that there are only a nite number of primes. Let the primes be p1 , p2 , . . . , pk in increasing
order, and consider n = (p1 p2 pk ) + 1. because n > pk , n is not prime (By assumption pk is the
largest prime). Furth
CS4050: HW #4
When all elements are equal, line 5 of PARTITION will be executed every time. Therefore the
value returned will be r. One way to modify PARTITION to return q = (p + r)/2 in this case is to
count inside the loop, the number of
CS4050: HW #3
Exercise 4.3-5. We need to show that: T (n) = O(nlg(n) and T (n) = (nlg(n). Below I use
inequality 3.16 of the text which is x/(1 + x) ln(1 + x) x) for x > 1 which imply that
x/(1 + x) ln(2)lg(1 + x) x for x > 1.
T (n) = O(nlg(n)
We need to
CS4050: HW #6
Exercise 9.1-1 Run a tournament on n numbers: Compare numbers in pairs and keep smallest
(the winner) of each pair for the next round. In each round, the size of the problem is halved until
only one number remains. The last remaining number
CS4050: HW #1
Exercise 2.1-1. First 26 is inserted before 31 and 41, then the second 41 is inserted between the
first 41 and 59, and finally 58 is placed between 41 and 59.
F ound = f alse;
i = 1;
while i n and F ound = f alse do
if A[i] =
CS4050: HW #2
Exercise 3.1-1 Functions f (n) and g(n) are asymptotically nonnegative. This means that there exists positive n0 such that both functions are nonnegative for n n0 . Consequently max(f (n), g(n)
f (n) + g(n) for n n0 . For any n, we have f (
CS4050/7050: Exam 1
1 (10 points).
Give an example of two asymptotically
(J I [
gin) that cannot be ,cornpar~ using any of the asymptotic notation.
=- ~ WI. f\.
ctions I(n) and
CS4050: HW #9
A counter example for selecting least duration activity: a1 = [1, 10), a2 = [11, 20), and a3 =
[9, 12). Activity a3 is selected rst and no other activity can be selected after that. However, in the
optimal solution activities