Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Recursion question (http://www.alice.org/community/showthread.php?t=9714)

cedricdosss 11-30-2012 06:12 AM

Recursion question
 
7. Which of the following is best describes “recursion”:

a. It is a loop identified during programming by the reserved word: RECURSION.
b. It is a programming technique.
c. It is a complex technique that should be avoided.
d. It is similar to a random number generator.
e. It is most like an infinite loop.

I think the right answer is B


10. In Chapter 7, Table 7-2, of “Starting Out with Alice”, there are a number of functions associated with Lists. Suppose that you used the ‘size of list’ function on a list and it returned a value of 10. The list function “First item from list” returns the first item in the list. As noted, it is in position 0. Using the function “Last item from list”, then would return the last item. What “position” is this last item?
a. Zero
b. One
c. Nine
d. Ten




4. Which one of the following statements is true:
a. A class cannot contain more than one method.
b. The color red is an example of a method.
c. Methods are part of a class.
d. Methods in one class cannot call methods of another class.

x2495iiii 11-30-2012 01:00 PM

We can't help you with homework by simply telling you the right answers, but we can help you figure it out.

For the first question, do you know what recursion is? It's when a method calls itself. Think about what that means.

Second question: You should be able to figure that out yourself. If you're having trouble with simple questions like that, you're either not trying, or you need help from the teacher. Ask him/her after class if you can have some things explained to you. I'm really not trying to be a jerk here, I'm just trying to keep you from burning yourself later on.

Third question: Two of the options are ridiculous and can be eliminated immediately. To find which of the two remaining options is right, you need to know what a class is, and what kinds of things classes can do.

nitp18 01-24-2013 02:55 AM

x2495iiii

tell answers :)

Brettlee 06-07-2013 06:17 AM

I think that the right answer is "d". Am I right??

hollyrbraswell 01-29-2016 11:45 PM

i know this much only recursion is the repeated application of a recursive procedure or definition.

chickentree 01-31-2016 04:20 PM

Recursion
 
In order to forget recursion,you must first forget recursion.
Is a toung in cheek way to remember it.

On the one hand recursion can be an elegant solution to a complex problem while on the other hand, it's execution can be slow and resource intensive (using lot of memory, disk space or both.)

Basically, if you can beappreak a problem's solution into smaller and easier to solve problems, you can use recursion to solve it. At the same time it should probably be made clear that any recursive method can be rewritten in a non-recursive way.
A silly example:
[CODE]
count(int)
if(int>0)
return(count(int-1)+1) // the call that makes this a recurrence
else
return(0) // the condition that cause the recursion to end.

So count(3) would result in:
count(3)
return(count(2))+1
return count(1)+1
return(count(0)+1)
return(0)
[/CODE]
Which would call itself 4 times until the argument was 0 and then begin ending each recursive step back up the call chain returning 0, 1 , 2, and finally 3. Note that while the function is recurring, none of the previous calls can end. This is what uses up resources.

Hope this helped,


All times are GMT -5. The time now is 01:27 PM.

Copyright ©2017, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.