If a method calls a recursive method, does that make the method recursive as well?

• November 9th, 2013, 11:42 AM
EDale
If a method calls a recursive method, does that make the method recursive as well?
I think the answer is yes, but I'm not 100% sure. For example:

Code Java:

``` public E last() { return root.getRightMostData(); }   public E getRightMostData() { if (right == null) return data; else return right.getRightMostData(); }```

Does this mean last() follows the recursive model?
• November 9th, 2013, 11:52 AM
Norm
Re: If a method calls a recursive method, does that make the method recursive as well?
I wouldn't think so. last() does not call itself.
• November 9th, 2013, 10:12 PM
ChristopherLowe
Re: If a method calls a recursive method, does that make the method recursive as well?
I like to think of recursion as a property of an algorithm instead of a property of a method. So I would argue that .last() is recursive because functionally that is what it is doing.
• November 10th, 2013, 03:39 AM
GregBrannon
Re: If a method calls a recursive method, does that make the method recursive as well?
@ChristopherLowe

I think your perspective is reasonable and even helpful to forming an answer to a more general question. I think your perspective requires one to define the boundaries of an algorithm. At some point an algorithm is separate from the enclosing program. I would think the boundary of an algorithm is the point at which the algorithm can stand alone: it accepts input according to its documented interface, and from those inputs provides output(s) according to its function. In the OP's example, I would consider last() outside the boundary of the algorithm. last() is not required for the algorithm to function, and last() adds no value. last() is a call to the algorithm which could instead call another method that calls another method that . . . calls another method that calls getRightMostData().

Further, the OP asked a specific question about recursive methods in the thread title which I believe Norm answered correctly according to the definition of a recursive method. In fact, the Wikipedia article classifies last() as a wrapper function, a term I haven't heard before in this context, but the explanation makes sense.
• December 9th, 2013, 09:40 AM
ChristopherLowe
Re: If a method calls a recursive method, does that make the method recursive as well?
I came across something in my copy of "Ada Plus Data Structures: An Object Oriented Approach" (1996) that deserves a slight necro-post. In the front cover I've written a tonne of exam notes including:

• Self recursion
• Mutually recursive
• Recursive chain

However this wasn't mentioned in the 30 odd pages on the subject (really good book btw). I dug through my lectures notes and definitely wrote them down while going over Sets and Lists but it wasn't much.

GregBrannon makes a good counter case and I can't find anything more authoritative that my own 12 year old lecture notes. This simply comes down to my own opinion but I still think that .last() should be treated as recursive. Given OP's code fragment and the spirit of the question I am assuming that nothing is being overloaded and 'root' is a type of this class. .getRightMostData() has a base call, a call on itself and a recursive memory profile and by my previous assumption .last() does as well. The designers of this class would have considered what would happen if 'root.right' points to itself or forms a daisy chain and chosen recursion as the most elegant solution.

I think Norm's answer is correct in the broadest and most practical sense. I think my answer is correct but from a specific, design orientated perspective. It's the less correct answer because it's rare to consider these kinds of data structure implementations in modern languages like Java.