Ask your own question, for FREE!
Mathematics 10 Online
OpenStudy (anonymous):

What does the following algorithm return? f(n){ if (n < 2) return 1 else return f(n – 1) * n:

OpenStudy (anonymous):

Would it not depend on the value of 'n'?

OpenStudy (kinggeorge):

This looks like the recursive algorithm for finding the factorial of n.

OpenStudy (anonymous):

Let's assume 'n' is 3, It would return 3X2 = 6. How is that the factorial?

OpenStudy (kinggeorge):

3*2*1=6

OpenStudy (anonymous):

well it is in that case, i just realized but what if it was 4?

OpenStudy (kinggeorge):

4*3*2*1=24

OpenStudy (anonymous):

It just multiplies 4X3, not 2 and 1.

OpenStudy (anonymous):

f(n-1) * n

OpenStudy (kinggeorge):

it multiplies \(f(3)*4 =6*4=24\) since \(f(3)=6\)

OpenStudy (anonymous):

looks like the recursive definition of factorial right?

OpenStudy (anonymous):

so n!

OpenStudy (kinggeorge):

exactly.

OpenStudy (anonymous):

yes, that is it. multiply n - 1 th number by n

OpenStudy (anonymous):

Ok thanks

OpenStudy (anonymous):

Alright. I'll take your word for it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
laylasnii13: Who wanna write or make a song with me???
2 hours ago 0 Replies 0 Medals
kaelynw: art igg
1 hour ago 9 Replies 1 Medal
XShawtyX: Art
19 hours ago 6 Replies 0 Medals
Nina001: teach me how to draw or just tell me the basics
22 hours ago 2 Replies 1 Medal
XShawtyX: We doing another drawing gimme ideas to add to this
23 hours ago 9 Replies 1 Medal
RAVEN69: What is x 3+y 3+z 3=k
1 day ago 20 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!