hello guys,

i lean C, which is my first programming language.

I'm having such a hard time with recursion, I don't think that I got the whole idiea

and still, having hard time to implement it.

My problem is to write functions based on recursion, however if you give me to read a code, I will be fine.

How did you learn recursion? what do you think that I should to in order to learn it?

thank you

# hard time with recursion

Page 1 of 1## 4 Replies - 743 Views - Last Post: 21 March 2013 - 12:37 AM

##
**Replies To:** hard time with recursion

### #2

## Re: hard time with recursion

Posted 20 March 2013 - 06:58 AM

Quote

How did you learn recursion?

I can't say that I have really learned recursion. I usually try to avoid it like the plague. For most of my career I programmed memory constrained devices where recursion was not an option.

Quote

My problem is to write functions based on recursion, however if you give me to read a code, I will be fine.

No that's not how it works. You provide your code that you don't understand and we try to answer your specific questions.

Jim

### #3

## Re: hard time with recursion

Posted 20 March 2013 - 09:24 AM

You need to start with a simple example. Try writing a recursive solution to the Fibonacci numbers. There are many examples of it on the internet, but you'll learn it better if you figure it out on your own.

### #4

## Re: hard time with recursion

Posted 20 March 2013 - 01:37 PM

chenfire, on 20 March 2013 - 05:49 AM, said:

My problem is to write functions based on recursion, however if you give me to read a code, I will be fine.

How did you learn recursion? what do you think that I should to in order to learn it?

thank you />

How did you learn recursion? what do you think that I should to in order to learn it?

thank you />

I'd recommend not focusing on how to write the function at first. My preference is to grapple with the conceptual problem first (and sometimes trying to write the function can help), but it sounds like you are still working through the concepts.

I haven't mastered this either, but when I was regularly assigned recursion problems I found this web example to be a helpful refresher.

http://www.cs.cmu.ed...se/hanoiex.html

Post some code once you've tried some examples and I'm sure the group will respond with helpful feedback.

### #5

## Re: hard time with recursion

Posted 21 March 2013 - 12:37 AM

Common places where recursion is used would be:

quick sort

merge sort

binary search

Greatest Common Divisor (GCD Euclid's method)

Fibonacci numbers

...

If you do a web search on the above, you should find loads of example recursive code

But practice writing your own routines ... and learn when NOT to use recursion.

quick sort

merge sort

binary search

Greatest Common Divisor (GCD Euclid's method)

Fibonacci numbers

...

If you do a web search on the above, you should find loads of example recursive code

But practice writing your own routines ... and learn when NOT to use recursion.

Page 1 of 1