# Questions regarding Recursion...

This topic is 4188 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey there everybody. I've been programming for a bit now, and things have been great. Right now however, I'm at a wall. I just started touching on the concept on Recursion, and it makes sense when ever I think about it - that being taking a complex problem, and breaking it down in to little pieces to solve it. My issue however, is coming up with the algorithms to solve certain issues. For example, I'm working on the Towers of Hanoi problem right now, which I understand is popular among learning programmers. I have the solution, which makes sense when I look it over for the most part, but my problem is I don't understand how the algorithm is made based on the information given by most texts describing the Towers problem. Is this something that grows on a programmer in time? Did any of you have a difficult time really grasping the recursion thought process? Sorry about all the questions, I just freak out whenever I hit a wall like this and start having those "am I really cut out for this" thoughts. Any and all help and comments would be greatly appreciated, thanks in advance.

##### Share on other sites
Quote:
 Original post by IshiomaHey there everybody.I've been programming for a bit now, and things have been great. Right now however, I'm at a wall. I just started touching on the concept on Recursion, and it makes sense when ever I think about it - that being taking a complex problem, and breaking it down in to little pieces to solve it. My issue however, is coming up with the algorithms to solve certain issues. For example, I'm working on the Towers of Hanoi problem right now, which I understand is popular among learning programmers. I have the solution, which makes sense when I look it over for the most part, but my problem is I don't understand how the algorithm is made based on the information given by most texts describing the Towers problem. Is this something that grows on a programmer in time?

Yes.

Quote:
 Did any of you have a difficult time really grasping the recursion thought process?

I don't think it ever bothered me too much. However I know that many (probably most) people do have a difficult time with it at first, so don't worry about it.

Quote:
 Sorry about all the questions, I just freak out whenever I hit a wall like this and start having those "am I really cut out for this" thoughts.Any and all help and comments would be greatly appreciated, thanks in advance.

Again, don't worry. You'll get it eventually, if you keep at it.
Also, you don't really need to apologize for asking a lot of questions. That's how you learn and that's what these forums are for primarily (at least in theory).

I recommend reading some basic, introductory, functional programming literature. They usually talk quite a lot about recursion, since it's so important in functional programming.

EDIT: Grammar

[Edited by - Roboguy on June 23, 2007 11:24:00 PM]

Quote:

[lol]

##### Share on other sites
creating recursive algorithms/recurrence relations aren't that hard. just study the examples, then do the exercises one-by-one starting at #1 (or all odd ones that are in the back of the book) until you get the hang of it. start with the base case(s), work your way up and try to find that 'pattern' (as you work your way up, see what changes and why).

[Edited by - yadango on June 24, 2007 1:06:43 AM]

##### Share on other sites
Quote:

Man, that's just not right. [grin]

Why not try starting out with a simple binary tree or even a linked list? Come back to the tower of Hanoi prolem later. Recursing nodes in a list or tree is pretty straightforward. My first attempt at recursion was to add random numbers to a binary tree so that the lower number was always sent to the first node and the higher number was sent to the second. When you recurse the tree, the output would always be in order.

##### Share on other sites
My tip on recursion is: if you can think of a way of solving a problem by solving groups of it, being each of those groups the same problem as the bigger one, you can use recursion to do that. You just gotta have a way to stop that recursion, which is when you have solved one of those small problems by a trivial, probably, method.

That's how ordering can be done. Think about merge sort. You can sort a list by splitting it into 2, sorting them and merging into a single ordered one. You can't sort a list of 1, so you just leave it alone. When merging 2 lists of a single item each, the sorting begins.

That's also how you can traverse a graph. You can think of the next graph to be traversed as a graph that does not contain the current node, so you mark it as visited and call recursion for adjacent nodes.

##### Share on other sites
Quote:

Haha, it took me a sec to get it. I thought you messed up the link at first glance.

Thanks a bunch for the replies. I found that when I actually sat down and physically tried out the Hanoi problem, it was alot easier to think about the pattern than it was using the vague pattern given in the text.

##### Share on other sites
Quote:
LMAO, that's a good one. Really made me laugh out loud![lol]

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013306
×