Jump to content
  • Advertisement
Sign in to follow this  
Ishioma

Questions regarding Recursion...

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Ishioma
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?

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]

Share this post


Link to post
Share on other sites
Quote:
Original post by erissian
There was a great thread about this recently. I highly recommend reading it here.


[lol]

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by erissian
There was a great thread about this recently. I highly recommend reading it here.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by erissian
There was a great thread about this recently. I highly recommend reading it here.


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 this post


Link to post
Share on other sites
Quote:
Original post by erissian
There was a great thread about this recently. I highly recommend reading it here.
LMAO, that's a good one. Really made me laugh out loud![lol]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!