# Welcome back

## Find a book, put up your feet, stay awhile

Sign in with Facebook

Sorry, we are unable to log you in via Facebook at this time. Please try again later.

or

Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more

Download

Standard view

Full view

of .

Look up keyword

Like this

Share on social networks

0Activity

×

0 of .

Results for: No results containing your search query

P. 1

Classes.soe.Ucsc.edu Cmps102 Fall01 Solutions 2Ratings: (0)|Views: 1|Likes: 0

Published by Ashok Chakravarthy

See more

See less

https://www.scribd.com/doc/90830278/Classes-soe-Ucsc-edu-Cmps102-Fall01-Solutions-2

04/23/2012

text

original

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMSASSIGNMENT 2SOLUTIONSProblem 1.

ni

=1

i

2

=

n

(

n

+1)(2

n

+1)6

for

n

≥

1.

Solution.

The proof will be by induction on

n

. The base case is

n

= 1. Theleft-hand side of the equation becomes

1

i

=1

i

2

= 1 and the right-hand side is

1(1+1)(2+1)6

=

2

×

36

= 1. Thus the base case holds.Now assume that the above equation hold for

n

=

k

−

1 where

k

∈

N

is someconstant such that

k

−

1

≥

1. Thus in,

k

i

=1

i

2

=

k

−

1

i

=1

i

2

+

k

2

we can replace the second summaion and get,

k

i

=1

i

2

=(

k

−

1)(

k

−

1 + 1)[2(

k

−

1) + 1]6+

k

2

=

k

(

k

−

1)(2

k

−

1)6+6

k

2

6=

k

[(

k

−

1)(2

k

−

1) + 6

k

]6=

k

(2

k

2

−

3

k

+ 1 + 6

k

)6=

k

(2

k

2

+ 3

k

+ 1)6=

k

(

k

+ 1)(2

k

+ 1)6.Thus the equation holds for some

k

given that it holds

k

−

1. By induction it followsthat the equation holds for all

n

∈

N

.

Problem 2.

ni

=0

x

i

=

x

n

+1

−

1

x

−

1

for

x

= 1 and

n

≥

0.

Solution.

The proof is by induction on

n

. The base case is

n

= 0. We prove it thus,

0

i

=0

x

i

=

x

0

= 1 =

x

1

−

1

x

−

1.Now, assume that the equation is true for some

k

∈

N

and

n

=

k

−

1

≥

0.Consider,

k

i

=0

x

i

=

k

−

1

i

=0

x

i

+

x

k

=

x

k

−

1

x

−

1+

x

k

Where the second equality comes from applying the induction hypothesis. Contin-uing,

k

i

=0

x

i

=

x

k

−

1

x

−

1+(

x

−

1)

x

k

x

−

1=

x

k

−

1 +

x

k

+1

−

x

k

x

−

1=

x

k

+1

−

1

x

−

1.Which is the desired result for

n

=

k

. By induction, the equation is true for all

n

∈

N

.

1

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMS ASSIGNMENT 2 SOLUTIONS 2

Problem 3.

Consider the following statement: the sum of cubes of the ﬁrst

n

positive integers is equal to the square of the sum of these integers. Restate this asa formal mathematical theorem using Σ-notation. Prove your theorem.

Solution.

Theorem 1.

For

n

∈

N

and

n

≥

1

,

n

i

=1

i

3

=

n

i

=1

i

2

.Proof.

The proof is by induction on

n

. The base case is when

n

= 1,

1

i

=1

i

3

= 1 =

1

i

=1

i

2

.Now assume that the theorem holds for

n

=

k

−

1 for some

k

∈

N

,

k

−

1

≥

1.Thus we get that,

k

i

=1

i

3

=

k

−

1

i

=1

i

3

+

k

3

=

k

−

1

i

=1

i

2

+

k

3

Where the last equation comes from applying the induction hypothesis. Now weuse the fact that

k

−

1

i

=1

i

=

k

(

k

−

1)

/

2 to show that,

k

i

=1

i

3

=

k

(

k

−

1)2

2

+

k

3

=

k

2

(

k

2

−

2

k

+ 1)4+4

k

3

4=

k

2

(

k

2

+ 2

k

+ 1)4=

k

2

(

k

+ 1)

2

4=

k

(

k

+ 1)2

2

.Which is the equation with

n

=

k

. Therefore, by induction, the theorem holds.

Problem 4.

n

5

−

n

is divisible by 5 for every positive integer

n

.

Solution.

The proof will follow by induction on the

n

. We prove the base case,

n

= 1, follows because

n

5

−

n

= 1

5

−

1 = 0 is divisible by 5.Now we assume that

k

5

−

k

is divisible by 5 for some positive integer

k

. Consider,(

k

+ 1)

5

−

(

k

+ 1) =

k

5

+ 5

k

4

+ 10

k

3

+ 10

k

2

+ 5

k

+ 1

−

k

−

1= (

k

5

−

k

) + 5(

k

4

+ 2

k

3

+ 2

k

2

+

k

)The ﬁrst term is divisible by 5 because of the induction hypothesis and the secondterm is divisible by 5 because is contains a factor of 5. Thus the sum is divisibleby 5. This proves the induction hypothesis and completes the proof.

Problem 5.

Find (and prove) an exact closed form solution to

f

(

n

) mapping thenatural numbers to the reals deﬁned by

f

(

n

) =

n

if

n

= 0 or

n

= 1,5

f

(

n

−

1) + 6

f

(

n

−

2) otherwise.

CS 102: INTRO. TO THE ANALYSIS OF ALGORITHMS ASSIGNMENT 2 SOLUTIONS 3

Solution.

Claim:

f

(

n

) =

17

6

n

−

17

(

−

1)

n

.

The proof is by induction on

n

.

Base:

(note that there are

two

base cases since the recurrence uses two previousvalues

f

(

n

−

1) and

f

(

n

−

2)).n=0 :

f

(0) =

6

0

7

−

(

−

1)

0

7

=

17

−

17

= 0, and we have

f

(0) = 0 by the recursivedeﬁnition of

f

.n=1 :

f

(1) =

6

1

7

−

(

−

1)

1

7

=

67

+

17

= 1, and we have

f

(1) = 1 by the recursivedeﬁnition of

f

.

Inductive Step:

Assume

n >

1. Assume

f

(

j

) =

17

6

j

−

17

(

−

1)

j

, for all

j

suchthat 0

≤

j < n

. Let IH(

j

) be the statement

f

(

j

) =

6

j

7

−

(

−

1)

j

7

, so we are assumingIH(

j

) for 0

≤

j < n

. We need to show that

f

(

n

) = 6

n

/

7

−

(

−

1)

n

/

7.Since

n >

1, we can use the recursive deﬁnition of

f

to get that

f

(

n

) = 5

f

(

n

−

1) + 6

f

(

n

−

2).We can use IH(

n

−

1) and IH(

n

−

2) to rewrite

f

(

n

−

1) and

f

(

n

−

2). So from theinductive hypothesis we get:

f

(

n

) = 5

6

n

−

1

7

−

(

−

1)

n

−

1

7

+ 6

6

n

−

2

7

−

(

−

1)

n

−

2

7

=5

×

6

n

−

1

7+6

×

6

n

−

2

7

−

5

×

(

−

1)

n

−

1

7

−

6

×

(

−

1)

n

−

2

7=6

n

−

2

7[5(6) + 6]

−

(

−

1)

n

−

2

7[5(

−

1) + 6]=6

n

−

2

7(36)

−

(

−

1)

n

−

2

7(1)=6

n

−

2

7(6

2

)

−

(

−

1)

n

−

2

7(

−

1)

2

=17

×

6

n

−

17(

−

1)

n

which is what we needed to show.

Problem 6.

Deﬁne the following recurrence

F

(

n

) =

1 if

n

= 06 if

n

= 16

F

(

n

−

1) + 9

F

(

n

−

2) for all

n

≥

2Show that

F

(

n

)

≥

n

3

n

for all

n

≥

0.

Solution.

Proof

by induction on

n

.

Note that there will need to be two base casesfor this induction proof. One (

n

= 0) is not suﬃcient because then our inductivestep would have to cover 1

,...,n

. This presents a problem because our recurrenceis not deﬁned for

n

= 1. In general when there are two recursive references to afunction like

F

, namely

F

(

n

−

1 and

F

(

n

−

2), two base cases are required for aproof by induction.

Base Step:

n

= 0: By deﬁnition

F

(0) = 1

≥

(0)3

0

= 0.

n

= 1: again we have

F

(1) = 6

≥

(1)3

1

= 3.

- Read and print without ads
- Download to keep your version
- Edit, email or read offline

© Copyright 2015 Scribd Inc.

Language

Choose the language in which you want to experience Scribd:

Sign in with Facebook

Sorry, we are unable to log you in via Facebook at this time. Please try again later.

or

Password Reset Email Sent

Join with Facebook

Sorry, we are unable to log you in via Facebook at this time. Please try again later.

or

By joining, you agree to our

read free for two weeks

Personalized recommendationsbased on books you love

Syncing across all your devices

Join with Facebook

or Join with EmailSorry, we are unable to log you in via Facebook at this time. Please try again later.

Already a member? Sign in.

By joining, you agree to our

to download

Personalized recommendationsbased on books you love

Syncing across all your devices

Continue with Facebook

Sign inJoin with emailSorry, we are unable to log you in via Facebook at this time. Please try again later.

By joining, you agree to our

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

CANCEL

OK

You've been reading!

NO, THANKS

OK

scribd