Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,217 members, 7,818,743 topics. Date: Sunday, 05 May 2024 at 11:50 PM

Resources To Learn Recursion In Java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Resources To Learn Recursion In Java (2066 Views)

Resources To Teach You Programming / 15 Resources To Learn Python Programming Language / I Want To Develop A Software In Java To Calculate CGPA (2) (3) (4)

(1) (Reply) (Go Down)

Resources To Learn Recursion In Java by logic101: 1:15pm On Jan 13, 2012
omoto dun , fayimora ,and the rest,Please whats the best resource to learn and understand recursion in java
Re: Resources To Learn Recursion In Java by Fayimora(m): 3:09pm On Jan 13, 2012

Recursion requires intuitive thinking. Its not a concept you can learn with some resource. Yeah they can get you started but they can't get you to think recursively. The way I learnt it was by reading books and then solving A LOT of problems with recursion. When I say problems I mean problems like  [log(n) or n log(n) sorting algorithms], [Tree, Graph and Disjoint set algorithms] and any other stuff I can get my hands on.

Just make sure you remember that if you still find yourself confused after practicing for 1 month, you are not dull.lol Seriously, recursion takes time and soon enough, you would just get the whole thing.

Resources to get you started ? Errm use anything at all,  lol but since you said Java, am guessing you want to see some code first.
- Any book with recursion in it.

Start with a normal book, then move to one that concentrates on Algorithms and Data Structures.

Tip: You might find yourself asking this, "How does it work?". My answer is YOU DO NOT NEED TO KNOW.

If you want an example of what I mean by my above tip, am happy to lay one or two down.

Goodluck!
Re: Resources To Learn Recursion In Java by ektbear: 7:10pm On Jan 13, 2012
A good way to think about recursion is a stack of books.

Think about the factorial function.

How is it defined?


Factorial(n) = 1 if n==0
                 n*Factorial(n-1) for n>0


So how do I compute Factorial(5)?

Well, the answer is 5 times Factorial(4). So I label a book with "Factorial(5)=5 * Factorial(4)", put it on my desk.

Ok, so now I need to compute Factorial(4). I'll have to place another book on top of the previous one labeled "Factorial(4)=4 * Factorial(3)".

And so on and so forth.

At the end of this process, the top book on my pile is labeled "Factorial(1) = 1*Factorial(0)". Well, that label by definition is just equivalent to "Factorial(1)=1."

So now I can start removing books from my pile. I can remove the first one, and write down Factorial(1)=1 on a sheet of paper.

then I can remove the second one, getting "Factorial(2)=2." And so on and so forth. Until I reach the bottom book on the pile, which gives me the answer I want.

Basically, recursion is equivalent to the stack data structure. I believe that this is how computers implement recursion also.
Re: Resources To Learn Recursion In Java by ektbear: 7:24pm On Jan 13, 2012
The key mistake a lot of people (including me when I first learned about it) make when they think about recursion is that they know how to build up this conceptual pile of books. But sometimes they forget you also have to remove all the books from the pile before you can get your answer.
Re: Resources To Learn Recursion In Java by lordZOUGA(m): 10:25pm On Jan 13, 2012
U just described a for loop iteration, Though it is right to some extent but whenever the function calls itself recursively it starts from the beginning of the problem until it gets to the base problem (which you must have solved) and solves other reccuring problems using that base solution then leaves the loop when it gets to an exit statement. Using a function recursively exposes the programmer to the risk of stack overflow unless you make a memo or an array that stores the value of all problems solved to prevent the function from starting at the beginning with every recursive call,
Re: Resources To Learn Recursion In Java by logica(m): 10:03pm On Jan 14, 2012
lordZOUGA:

Using a function recursively exposes the programmer to the risk of stack overflow unless you make a memo or an array that stores the value of all problems solved to prevent the function from starting at the beginning with every recursive call,
Is that actually how you prevent stack overflow?
Re: Resources To Learn Recursion In Java by lordZOUGA(m): 10:08pm On Jan 14, 2012
no it is not, But using that method reduces the risks,
Re: Resources To Learn Recursion In Java by logic101: 10:16pm On Jan 14, 2012
Fayimora:


Recursion requires intuitive thinking. Its not a concept you can learn with some resource. Yeah they can get you started but they can't get you to think recursively. The way I learnt it was by reading books and then solving A LOT of problems with recursion. When I say problems I mean problems like  [log(n) or n log(n) sorting algorithms], [Tree, Graph and Disjoint set algorithms] and any other stuff I can get my hands on.

Just make sure you remember that if you still find yourself confused after practicing for 1 month, you are not dull.lol Seriously, recursion takes time and soon enough, you would just get the whole thing.

Resources to get you started ? Errm use anything at all,  lol but since you said Java, am guessing you want to see some code first.
- Any book with recursion in it.

Start with a normal book, then move to one that concentrates on Algorithms and Data Structures.

Tip: You might find yourself asking this, "How does it work?". My answer is YOU DO NOT NEED TO KNOW.

If you want an example of what I mean by my above tip, am happy to lay one or two down.

Goodluck!

Thanks bro ,I would keep trying to understand .
Re: Resources To Learn Recursion In Java by ektbear: 1:29am On Jan 15, 2012
Mergesort is another useful algorithm for understanding the power of recursion.

You might want to read or reread about it, then implement it yourself in Java.

(1) (Reply)

About Matlab / I Want To Learn How To Create Mobile Applications / Java Challenge

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.