4 Replies - 348 Views - Last Post: 21 March 2013 - 12:37 AM Rate Topic: -----

#1 chenfire  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 13-March 13

hard time with recursion

Posted 20 March 2013 - 05:49 AM

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 :)

Is This A Good Question/Topic? 0
  • +

Replies To: hard time with recursion

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,753
  • Joined: 25-December 09

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
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

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.
Was This Post Helpful? 0
  • +
  • -

#4 Switters  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 105
  • Joined: 03-June 12

Re: hard time with recursion

Posted 20 March 2013 - 01:37 PM

View Postchenfire, 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 :)/>


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.
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,764
  • Joined: 20-September 08

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1