Get the Code: http://goo.gl/S8GBL

Welcome to my Java Recursion tutorial. In this video, I’m going to cover java recursion in 5 different ways. I figured if I show it using many different diagrams that it will make complete sense.

A recursive method is just a method that calls itself. As these calls are made the problem gets simpler until you reach a condition that leads to the method no longer making calls upon itself. This is known as the base case.

So triangular numbers are just the summation from 1 to N?

I have no idea whats going on in your first example?

In order to understand recursion, you must first understand recursion

You sound like Andy Bernard from the Office. Also, thanks for the video explaining recursion, this makes a lot more sense to me seeing what happens at each step 🙂

0:00 – 2:04, Explained it better than every other video

the "else" doesn't make any sense here.

I actually came here because I was trying to make a merge sort algorithm and wanted a better understanding of recursion before starting. Thanks for covering merge sort too very helpful.

chutiya sala

Are you teaching yourself?

A little fast for me but thanks for the video. Glad I have a pause button

Dude, you freaking rock!

won't it be return from method 2 and forward instead of returned?

I might getFACT on my final tomorrow

Hey, do you have a video on DEqueue and Circular queue? If yes, please send the link.

RAM killer.

If you slow the video down to 0.75x, it's much easier to understand and comprehend. There's also the side effect of the presenter sounding like he's on drugs.

i didn't get it

when i see "else" i do whats under it then continue on .

i dont go back to "if" because the "if" condition didnt match in the first place.

Sorry, but there are videos on YouTube which explain recursion much simpler!

I wish I could explain stuff like this guy does.

Great work explaining how factorials work but not so much explaining the code steps … hard to follow mate

I know this is an old video but can you explain the GO UP part at 1:45? I don't understand why it goes back through the previous iterations instead of just .returning a 1

Isn't this "in place merge sort"?

Hi Derek, how are you? Thank you for your tutorials, I just wanted to ask if you have any good links or places to do exercises on algorithms. I dont mean like textbook stuff, that really does not help, but mainly like "make a program" type of deal if you know what I mean. Do you by chance have any handy? Thanks again!

SAY "TRIANGULAR NUMBER" ONE MORE TIME

Thanks sir. The explanation of the recursive methods was very good and it made it easier for me to understand that. Though, the later portion of the video was too complicated for me. Thank you for the video. I guess I will also use the same way as you to teach my viewers about recursion. Cheers 👏

Awsome, but these examples all had a base case of one. Could you do an extra video for recursion problems with more than one base case? Also, could you cover recursive permutation as well? Where you can print out every possible combinations for letters in a word?

Can you direct me to which Eclipse IDE you downloaded on your Mac? I couldn't find the right one.

Very well explained, thank you very much for this. Just subscribed~!

Derek thank you so much. Youtube is awesome because of the content creators likes you.

Tried watching it with closed captions and it's impossible to follow…

Thanks for the great explanation and the effort you put into making the video!

I'm quite a beginner, and it might be a very stupid question, but once number equals 1, and it reaches the 'return 1;', why does it go forward into the 'else' section again?

Actually, for triangular numbers, you can calculate it like this:

public int getTriNum(int num) {

return (num + (num * (num – 1) / 2));

}

Or a bit more understandably:

public int getTriNum(int num) {

for(int i = 1; i <= num; i++) num += i;

return num;

}

And for factorials, you can also do it without recursion:

public int factorial(int num) {

for(int i = 1; i < num; i++) num *= i;

return num;

}

But factorial still is a pretty good example, nevertheless.

Thanks again Derek. Much clearer now.

Why we need recursion if we have "while" or "if" ? Can you explain?

you talk too fast man .

Which software do you use to make your presentation?

Wow thank you so much. My data structures text book didn't explain at all how this works. I ran an example in the debugger and was extremely confused why it went "back up" once it hit the base case. You cleared it up in the first 2 minutes. Thank you!

wow, every time I struggle with x/y concept there is a video in your channel that helps me understand it 100%… Again, thank you Derek!!!!!

It's excelent explained, but all that non-using code and the comments are confusing me so much. Still a great video.

Thanks ….your voice is so catchy

.