Ask your own question, for FREE!
Computer Science 15 Online
kekeman:

Which of the following is a disadvantage of programs that use recursion? Code that is more difficult to read Faster performance Higher memory usage Programs that crash more often

Vocaloid:

@smokeybrown

blubabub:

what do you think is

kekeman:

I think it is either A or D

SmokeyBrown:

Out of the options listed, I think the main disadvantage would be a high memory usage. Whenever a function is called, memory needs to be allocated in order to store the variables and data structures involved in that function. Well, a recursive function is one that calls itself, usually doing so many, many times. Each of those calls takes an extra amount of memory. Compare this to a loop which does not have to allocate additional memory for each cycle; in that case, variables are defined once and can be reused Before, we used an example of people standing in a line, recursively asking the person in front of them what position they were. Well, for each of those recursive calls, each person has to remember "wait for the person in front of me to tell me what number they are, then I'll know what number I am". It's not a hard thing to remember, but each person that asks the question has to remember it; the more times the question is asked--or, the more recursive calls are made--the more the need for memory multiplies. That's a kind of rough analogy that might help to illustrate the concept The other options don't make much sense by comparison. While recursion might be confusing to someone who isn't familiar with the concept, it could be argued that recursion is a more "elegant" solution to some problems, so readability isn't necessarily an issue Faster performance isn't a "disadvantage," it's actually usually preferable As long as they are written properly, I don't know that recursive functions tend to crash more often compared to non-recursive functions

kekeman:

Yeahh yeahh i see great points there

kekeman:

Amazing explaining

kekeman:

Because it says in my less that: Recursion is best used: To solve a large problem that is easily broken into smaller and smaller versions of itself To produce code that looks cleaner and is often shorter When amount of memory is not a concern

kekeman:

So i think that Higher memory usage would make sense

SmokeyBrown:

Ah, yeah, that makes sense. The point about "when memory is not a concern" does seem to imply that recursive functions have the potential to use a lot of memory. And I would agree with that

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!
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!