CS4050: HW #5
Exercise 8.1-1
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
Quiz 1
CS4050
08/27/12
1) Prove that 2n2 - 4n + 7 = (n2); give the values of the constants and
show your work.
[4]
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
Quiz 2
CS4050
09/10/12
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.
[7]
A) Please refer to your text book. The above question is the first of
-'1
I
I
!
10/28/13
Quiz 7
I
i
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.
[5J
t7;ryf
ffi ~
aCt-
(On
-1-
J-7' ~-rL -
~w;r Dd ~.
-itcfw_
I
i.
c-
01127114
CS40S0
Quiz 1
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
f,.J
k
f~e.
- 4-11
7" -
A-e"e
1
2.11
)./IIL -
q,/It
-rLs
C1.d
w~
Me>
Cv ,J;~i'.;N\ -t:~ek
L-Je.
e-
52 Uf)
~4-
VI
77"
A
(-
(WI:
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.
-r-
What prb'perty0) m~st a stable sorting algorithm satisfy?
-tk
()frJcfw_h'
'if ~I
eJePtf#1f~ (,'11
I
L, ,
~?Vvte. ,-eM-e-pvrt.
,'J
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
r
(I
,
CS4050/7050: Exam 2
J
Exercise
1 (20 points). Show that the running time of QUICKSORT is
ern')
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
Exercise
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,
after
one
r
, !l
,
7s 6 ~
b 3
2.
q s: 6 ? 2- l? 7
~ "c ~ q .l- .fl
'i
3
)
~
3
1,
1
-ill
.5'
J
.> Cf S
'Sifb. J
Jy
~r.r
rJ;
4L5f>7
s
CS4050: HW #10
Exercise 31.1-2
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
Exercise 7.1-2
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.
Exercise 2.1-3
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 (
- points) Solve the following recurrence re Ia tiIOns. Show your work and give
Exercise 6. (20
your answer \ terms of 8-notation.
, ,
I
,
v1
II
.AI>\
"
/\
:f t
vI
b-r
J\
-t -t .
ITT~T
I
"
/
2
/
Z:h",~
-r'C<I1~IAMI
CS4050/7050: Exam 1
ILr17>lb5
Exercise
o
1 (10 points).
Give an example of two asymptotically
t
(J I [
gin) that cannot be ,cornpar~ using any of the asymptotic notation.
L I'l)
Exer
=- ~ WI. f\.
lsU,):-
tL
(.35
ctions I(n) and
posit
CS4050: HW #9
Exercise 16.1-3
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