Ask
your own question, for FREE!
Mathematics
30 Online
What does the following algorithm return? f(n){ if (n < 2) return 1 else return f(n – 1) * n:
Still Need Help?
Join the QuestionCove community and study together with friends!
Would it not depend on the value of 'n'?
This looks like the recursive algorithm for finding the factorial of n.
Let's assume 'n' is 3, It would return 3X2 = 6. How is that the factorial?
3*2*1=6
well it is in that case, i just realized but what if it was 4?
Still Need Help?
Join the QuestionCove community and study together with friends!
4*3*2*1=24
It just multiplies 4X3, not 2 and 1.
f(n-1) * n
it multiplies \(f(3)*4 =6*4=24\) since \(f(3)=6\)
looks like the recursive definition of factorial right?
Still Need Help?
Join the QuestionCove community and study together with friends!
so n!
exactly.
yes, that is it. multiply n - 1 th number by n
Ok thanks
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!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
curriful:
Is there a maximum to how many emojis you can add onto a QC group? Or is it limit
zanesafoodie:
have any of you worked with a teacher that you physically just CAN'T suck it up a
Shadow:
Hello QuestionCove Users! Today we are officially announcing two promotions to our staff, @eiwoh2 (Howie) as our new Senior Moderator, and @axie as our new
Arizona:
I'm Doing the ACT testing tomorrow which I feel like I don't even want to try but my friends are making me.
Twaylor:
NASA's Artemis II will be going around the moon today at exactly 1 pm EST (right now) https://www.
lovelove1700:
I need help with this song. I just need the lyrics for the song, nothing more. I need it for a school project.
ARAAG:
I need help working on new song lyrics and ideas! If anyone could help me that wo
3 hours ago
2 Replies
0 Medals
9 minutes ago
2 Replies
0 Medals
9 hours ago
29 Replies
14 Medals
1 day ago
4 Replies
2 Medals
1 day ago
1 Reply
1 Medal
2 days ago
0 Replies
0 Medals
1 day ago
16 Replies
1 Medal