You are on page 1of 7

...

cs

225

Spring 2016

Homework O
Due January 25, 2016
in lecture and SVN
Instructions for submission into your
class SVN repository are on the webpage.

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 of CS225 , 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 to do so because we think it may help you diagnose and
remedy some things you might otherwise find difficult later on in the course. If this
homework is difficult, please consider completing the discrete math requirement (CSl 73
or MATH 213) before taking CS225.

Name:

A Jre.

N etID:

~.J ; c-, .-.

r,

v->

.~G.

Section (circle o~:

L,Md
Wednesday

7-9pm AYB

Thursday

9-llam AYC

11-lpm AYD

1- 3pm AYE

3-5pm AYF

5-7pm AYG

7-9pm AYH

9-lla

11-lpm AYJ

1- 3pm AYK

Friday

AYI

5-7pm AYM
Laptop Sections:
Thursday

1- 3pm AYN

3-5pm AYO

5-7pm AYP

Friday

9- llam AYQ

11-lpm AYR

1- 3pm AYS

JOut of 60

Grade
Grader

cs

Spring 2016

225

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 the class, and tagged by #HWOnuml. Also, use Piazza's code-formatting tools
to write a private post to course staff that includes at least 5 lines of code. It can be code of
your own or from a favorite project-it doesn't even have to be syntactically correct-but it
must be formatted as a code block in your post, and also include the tag # HWOnuml. (Hint:
Check http://support.piazza.com/customer/portal/ articles/1774756-code-blocking). Finally,
please write the 2 post numbers corresponding to your posts here:

Favorite Movie Post (Public) number:

I 55 o

Formatted Code Post (Private) number:

IS 5 I

2. (12 points) Simplify the following expressions as much as possible, without using an calculator ( 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.

IT ( :2)

(a)

1-

[ Answer for (a) :

:z._

k=2

~~ )

" ( I-

(I -

I - : ~ ) = ( i ~_,

(l

) (

:: ( {-, )( f; ) ( -% )( %) . ( L: \-)

.-+2

'

~ ) ( - :~)

_<:

((;Hi>;-)j ( tV~Cz-2)(~~) ... (~~0)((":'~)


(~ 1( 7)

~ ~ ( 1+

+;,

(b) 31000 mod 7


soo

( 1. 1..)

- L

""<>c

- ?..t;

:=

LJ

(;_ ,,0

- (
~

"-'O

)'

.. ,s c
( ~ J

Jt
I
-f

,._..., 1-

<>0

ou

Answer for (b ) :

'""'"'

:: L

- 1.
:::.

1-

SO

"-- oJ f

S'(<>)
1o

:::(~.,_)

~..,J t
,_,J 7

r~,3i -f
::: y """')
2

,-.,.,

::J

Y "o J f

cs

225

Spring 2016
CXl

(c)

I)~r
r=l

I Answer

i_ (~ \r _ !lM

::: I,~

"-tbO r~l

"2-

1 <; =-1,..,\
"....., -+ l.,. + !..'-\

t- . - . 1"

~ ~ ~ ~ ("\\,~
-4

b<)

(d) log78l
log7 9
:_

lo'\

=-

2.

~ ..!_

" ~ ;,,o

-?..,,_,

-t

-'-I

"l..

-t 1.."

t- - t- 'Z.. "

l.. '"I

--

~?1\~

t"\

(d):

LJ

Answer for (e) :

( 'L 1-)'Lrt

'C..

t"\

'L

- y {'\
(f) log 17 221 - log 17 13

Answer for (f):

1...1.... I
-:;:...

11' ~ )

'1

is r1..2.,
- ' 3,

it

C\

I
()

S-1---

=-I+

~l

(e) log 2 4 2n

::

'l.

I Answer for
81

I \

for (c):

'I(

\~
=,

~I

cs

Spring 2016

225
n

3. (8 points) Find the formula for 1+ L j ! j , and show work proving the formula is correct using
j=l

induction.

I Formula: I (

ft(\

t 1.

7- + 1

f\ t-

I)

!s+ -tn~r'\)

-= 1._ { I t '- 1. ) + 1 \ ""\ f (- 1 n =~ ~ +- 3 1. -S I- - - ,.. ~ ..., -= S . ( I ~ ~ ') + ~ !lJ


:=. Lf ~ ( I\. 4 ) ~ - ~ l n - 1) ~ (. ~ - l ~ +- "''. r- ::: " ~ +- f\ \ r, = I"\ ~ ( ~ t- l) ~ ( ~ 1 ) I.
l.}e w "' \- i..,. I, 1-ow ~+ I+-~'~'.
. :: ( l"l+t') ! r, 'tJ
E: IN,
:=:. I.
1

+ r ' "

t\

j-1\j

{1 "" !s<...
I

c.."- \.<..

<..~,f'

{+ ~
\ _,
u
"'

T~~ "- ~~

""'<...

0 ~!. ~

+ t :; ?. ~

,~l

l t- L. ~I - :

T~

I\\.'
y..,v

ndu .. h~

,~

(' :

l_ \.

= I 2 - -.

,.

Lw
1.
.

'I

"-1

It

'Z...
I

,...,J _: ~
):.'

6\-_'t

"/'

+n

n '

:::.

~w=-

n -

t- " . n

I\

(-t-

I"\

-::::.

+-~ .f"... '"' .... ) ~ ll.

J.::.l

'I.

(\.::+I )

( r. r I

( n .... l ')

4. (8 points) Indicate for each of the following pairs of expressions (J(n),g(n)), whether f(n) is
0, D, or 8 of g(n). Prove your answers to the first two items, but just GIVE an answer to
the last two.

(a) f(n)

::
\

....... 1.,~T

(b)

<;1-...,-...,

(,,, ': . ~
l

"\....

'-f

k } ()

k '- : f 1
"L

(")

vJ<!.

k=\

\\
4

"t..

f (,., 1 8 j l.--l

fh-..M-(--

.. )"\"

::

r:

J(n) _n__ g(n)

('I

o ,

\J ()

>G,z,

< lJ' -t- \

-f

n ~-2.'

I { { ,-.)

JL"

('Q-::.\.
I

~ ~ ~

c..u-kvil

(JL..__~

H..e..

3 K '>

g(n)

<J,;\l")

f(o}

<:_"

~'T

h..~

(l,.,,b(_

\ ,. ..._'1..-r;:;

~ r, 0

I Answe, fo, (b ), I

,~

1'1

E)

> 2 ~ F(") ::: ~

"

.LI.."'"
1

<;::DL-1\

> _1 t ; '.. ,-

,,\J

$@

:"! O :.::. (._

f (n) = n 2 and g(n) = ( v'2) 10' ' n.


"2_ "L

n 01

k, '\(")

>r,~,

f- J_
< n ..., -"
Lf-

.:.

f(n)

Answer for (a):

d n., Vn

'>~
::

= 2n + 1.

x.f
U'----

1_

(.La. 'rl..
k

"

k, ,k,,_

and g(n)

4log 4 n

()

-z._ \jn ~ 0

.{-r-~ {r

2/~),

{n) ,,fl_

> I

\.,.)

~ l c'.

\.._

cs

Spring 2016

225

(c) f(n) = log 2 (n!) and g(n) = nlog 2 n.

~\

{ ;)'-

;;: ~ L

I Answer

na

for (c):

J(n)

g(n)

I
,..
r. . <.. (\

(d) f(n) = nk and g(n) = c 11 where k and care constants and c > 1.
~IA_n_s,-ve_r_fo_r-(d_)_:~l~f-(n_)_(
~-g-(n)
.) ~

t:;,,o

\c.

<-

c..

""'

5. (9 points) Solve the following recurrence relations for integer n. If no solution exists, please
explain the result.
(a) T(n) = T(?)

+ 5.

-::. (r(~) r~) \- ~

=T(~.)
(b) T(n)

S) \- S) + c;

SK= TC,)

T(n - 1)

+ i, T(O)

,: . T ( (\ -1..) + r.-1
_!_

1.:.)1." ~ k <~ ,

ci~

=-

0.

S 1,"""

uui...,_~
~

Answer for (b):

< ::. I

l. ~

..)~"-') ti)

J .(. -,. . .

,r......J-

'- \

-.

1.

...1.rJ

c,

p..-..

Pl" .

\..

T _!_

n::.lc

I")

k -1

+~= T(l\-k)+~.L
t=- 0

.\-n -i_ + "~'

2.

-t

~------.

= T('\-<,)

I'\.::.

Answer for (a):

-=((T(~)

..., k.

T(l) = l; assume n is a power of 2.

f'1 - <...

"-'

=L
i=

'"'

-=L

f\-c..

'"~'

t.

(c) Prove that your answer to part (a) is correct using induction.

A')s'"'~
v- ........

' " ~ , \

g..,-'K

c ....

l~,i.. +,.,._
\"-._,,

<.

~.u-=- o. , ~

6t-.-\- T(
~

~-=- \

, kY, A,,"..._ A.A>


T(

-z_j

) ...

T (

S (~

0-

(.)

T(,.,) =S

\0 '

C'\ -1"' \

,J Z, ,. ~.
n )

c_J
I:. ~ \ . . \t.

st

la,-i_L i--1 =

~ l '-..........

I")

IN ~ ~

n = c ___)

~ ~ 1..,.)\ l'"'Jvt..."t
-t \-:

,;,,~ ~

O+ \.

fi..i r ( ,.!::) =_s k .... , = c; ,..\t '2. k .. 1

1- ... , \ -1
<.__)
,rl

+ c; -::

~ \ ~

= S lo\"'-"+ I

T(l) ~

kc 1.

ra-..,-

""

.k.. , L,"

.lr

\,,.}c_

("1

""'-

,_

7-.~ + I +

5 :.:

~ \ -1)

.s f.>+

t; t- l =

C,~~ <j +I "

f"

s ( $5 F ) + \
D-+-,)

cs

Spring 2016

225

6. (10 points) Suppose function call parameter passing costs constant time, independent of the
size of the structure being passed.
(a) Give a recurrence for worst case running time of the recursive Binary Search function in
terms of n, the size of the search array. Assume n is a power of 2. Solve the recurrence.

T ( " ')

~ 1 (fr ) +

8(

n=-2

l\

>

{c--,..,,..

~"~

= TC ,) + I~" <0c
... , I

= E) l,)

,.

~::.

l.

e (I) ~ E)(l~~y ')

0~

C~)

+E)C,)

Recurrence:

T.(n)-;:T

Base case:

T(t)~G(\)

Recurrence Solution:

(t..,~J

(b) Give a recurrence l'or worst case running time of t he recursive Merge Sort function in
terms of n, t he size of t he array being sorted. Solve the recurrence.

T ( ~) = 'L ( 7-

T( :~)

f :

+n
n

=-

1.. "'--=-

lkT(~tc)~nk

(nT(1)-t "Lun

-:::.

~9(~1

~~n~k
)
-.;::::7

Recurrence:

T( n) ~

Base case:

T Ct'\

Running Time:

n =- 1... \::

(n

1- \ ( : ) + "
-::.

lo"\'"'}

....

cs

Spring 2016

225

7. (10 points) Corn,ider the pseudocode function 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);

(a) What is the output when passed the following parameters: x = 2, n = 12? Show your
work (activation diagram or similar).
1. , vz_
~A-n-sw_e_r_fo_r-(a-)
~

f(

:~1-l\_O
_ C\_{_____

~f(1..'?-,b)

;L,f l L\

1_

l. c, .(.,

1 ')
i ~

1.

f (I (,,.,

('5~

I )
'l.

{,

I(,>< 1.Sf> )<{(1-SE.,

tt. ;

C>)

(,w

(b)

h.

't'o~

't/'~

o\

'

/\he_

f\,l"\<.\.Lo"

17\.\.~

~ ~

~ of
n.
(c) Write a recurrence that models the running time
this function. Assurn.e checks, returns , and arithmetic are constant time, but be sure to e-valuate all function calls. Hint:
what is lhe most n could be al each level of the recurrence?

ot

T(n) =- \

(~J)

T( CJ~ 8t\).
, ( \) -:: T (o) +

(tJ.

e c,,

<e

@<l

(d) Solve the above recurrence for the running time of this function.

As"""'"""<-

,~

T(")~

r(;.._)-t

c--.

;;, ... w-c.r

.f-

(',

2.(8)(1').

- T ( ~k ) + k 8 (l)
= I(,)+

7.__

~y

1.. le..

~ \ --")

~.: :i'

-= k

8(,)
7

= 8) (,)

~Set,') ( ~

You might also like