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
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 through
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 refe
-'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
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~
M
(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 st
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?" .
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, yo
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
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 n
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 i
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) l
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 un
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 a
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
- 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)
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