Вы находитесь на странице: 1из 7

CS 225 Spring 2013

Homework 0
Due Jan 18, 2013,
Instructionsfor submission into your
class SVN repositorywill be included with labOl.
The purpose of this assignment is to give you a chance to refresh the math skills we
expect you to have learned in prior classes. These particular skills will be essential to
mastery ofCS225, and we are unlikely to take much class time reminding you how to
solve similar problems. Though you are not required to work independently on this
assignment, we encourage you todo so because we thinkit may help you diagnose and
remedy some thingsyou might otherwise find difficult later on in thecourse.
Name: Cl,u.YO\.
netID: \
Section (circle one): vVed 7-9,
Thurs 9-11, Thurs 11-1, Thurs 1-3, Thurs 3-5, Thurs 5-7, Thurs 7-9,
Grade lout of60
Grader
1. (3 points) Using 140 characters or less, post a synopsis of your favorite movie to the course
piazza space under the "HWO tell me something!" notice, so that your post is visible to
everyone in theclass, andtagged by #HWOnuml. Also,describesomeplaceyou traveled this
winter break to a private post to course staff, also with the tag #HWOnum1. Finally, please
write the 2 post numbers correspondingto your posts here:
Favorite Movie Post (Public) number: @\q
SummerTravel Post (Private) number: , L lo
1
CS 225 Spring 2013
2. (12 points) Simplifythefollowingexpressionsas muchas possible,withoutusingancalcu-
lator (either hardware or software) . Do not approximate. Express all rational numbers
as improper fractions. Show your work in the space provided, and write your answer in the
box provided.
n+1
"I Answer for (a): I
2Y\
I
(b) 31000 mod 7
"'J (Ou
o
:: (_'1.) ....oD StrO /,- 5 ) 2.S
\.3 '" ;;:: :I co 1- 2. .50 '=, 1\0 =: J..
.2.(4) II2. =- .J(:2):3 , 4{ )3 ()
= ( 4 )I = ( '1) If == .2.C 7
::: 4(1)II -== 4- A . (4)2 2 .t::l
":. It
IAnswerfor (b): I
4-
00

(c) ::::: L.. - \
1' =1

- - \
I
-
-
,
-
,-
\
IAnswer for (c):
\
2
CS 225 Spring 2013
(d) log7
81
<= ~ 8\
log79
lojl
It>j
\..oj1
I Answerfor (d): I 2
I Answerfor (e): I 4-'Y'"\
I Answer for (f): I \
3
l.
CS 225 Spring 2013
n
3. (8 points) Findtheformulafor 1+2: j!j) andshowworkprovingtheformulais correctusing
j =l
induction.
I Formula:

o\-t) .s.y...trI;-! : LT 2.. j tj =:
l <:.\
't\+l 1'\ )
-t j ,;:. \-\- J + C,,-Il

:;: 2)
(V\-\ 'l.)
Q.E.\),
4. (8 points) Indicat e for each ofthefollowing pairs ofexpressions (f('17,), g('17,))) 'vvhet her f( '17,) is
0 ,0,or e ofg(n). Prove your answers to the first two items, butjust GIVE an answer to
the last two.
4
1og
(a) f(n) = 4 nandg(n) =2'17, +1.
(b) f(n) = '17,2 and g(n) = eV2)log
2
n.
jLY\J {v:\
nl. S\. ..rn
I Answer for (a): I
I Answer for (b): I
f(n )
f(n)
e

g(n)
g(n)
4
CS 225 Spring 2013
(c) f (n) -- log2n! and g(n) = n 10g2 n.
IAnswer for (c): I f(n) 0 g(n)
(d) f (n) =n
k
and g(n) =en where k, e are constants and cis>1.
IAnswer for (d): I f(n) 0 g(n)
5. (9 points) Solve the following recurrence relations for integer n. Ifno solution exists, please
explain the result.
(a) T(n) = +5,T(l) = I, assumen is a power of2.
i( ) \ ( ) -T ?1
.Jl. \
21.-
t.

L.:=- lOl'"
T(V\) = '\ --\- !>loJ '" Y\
IAnswer for (a): I "1('(1) s \09 t \
(b)T(n) =T(n - 1) T(O) = o.
-rl '" I.")

1..
s. -\\M:. 'nal( .,-M)'/\\A.. 1) U- <;". -n, Y\,
O'r \-1",
Answerfor (b):
5
CS 225 Spring 2013
(c) Prove that.your answer to part (a) is correct using induction.
base (lotSe ' let) \
'T(%-) ;- 5= l-\- 5l.(),\'l.n
v-rli>', ""i( fI;'\)t5 \-t5Lo<)'L.lV\+l)
= T( -\- ,0
-=..1-; 5 Loj... '" + 1) -= \-15lD
J
2.( \,\+1) D.
6. (10 points) Supposefunction call parameter passing costs constant time, independentofthe
size ofthe structurebeing passed.
(a) Give a recurrencefor worstcase runningtimeofthe recursive BinarySearchfunction in
terms ofn, thesize ofthesearch array. Assumen is a power of 2. Solve the recurrence.
\(1):(\
\"(""')-:. T(!l') -\- CL
T(f\)-t- -iCL
=- L\.'\- \'0J2(\. (
Recurrence:
Base case:
Recurrence Solution:
(b) Give a recurrence for worst case running time of the recursive Merge Sort function in
terms ofn, thesize ofthe array beingsorted. Solve the recurrence.
'i l ' J=- l \
\ (V\):: L 1( ) t(,h
g;27@] Tim,
. (-r(",\'('. l\ 0. VI +9J

CS 225 Spring 2013
7. (10 points) Consider the pseudocodefunction below.
derp( x, n )
if ( n == 0 )
return 1;
if( n %2 == 0
return derp( x-2, n/2 );
return x * derp( x-2, (n - 1) / 2);
(b) Briefly describewhat this function is doing.
'\ (())
IAnswer for (a):
(a) What is the output when passed the following parameters: x = 2, n = 12. Show your
work (activation diagram orsimilar).
4)09LP
(c) Write a recurrence that models t he running time ofthis function. Assume checks. re-
turns,and arithmeticareconstanttime, butbesuretoevaluate all functioncalls. [Hint:
wh at is the most n could be at each level ofthe recurrence?]
c\
\"l\'\) \(\:l 1)'\-C
(d) Solve the above recurrence for the running time of this function.
7

Вам также может понравиться