Learn Recursion in 8 minutes 😵

preview_player
Показать описание
recursion tutorial example explained

#recursion #tutorial #example

// recursion = When a thing is defined in terms of itself. - Wikipedia
// Apply the result of a procedure, to a procedure.
// A recursive method calls itself. Can be a substitute for iteration.
// Divide a problem into sub-problems of the same type as the original.
// Commonly used with advanced sorting algorithms and navigating trees

// Advantages
// ----------
// easier to read/write
// easier to debug

// Disadvantages
// ----------
// sometimes slower
// uses more memory
Рекомендации по теме
Комментарии
Автор

public class Main{

// recursion = When a thing is defined in terms of itself. - Wikipedia
// Apply the result of a procedure, to a procedure.
// A recursive method calls itself. Can be a substitute for iteration.
// Divide a problem into sub-problems of the same type as the original.
// Commonly used with advanced sorting algorithms and navigating trees

// Advantages
//
// easier to read/write
// easier to debug

// Disadvantages
//
// sometimes slower
// uses more memory

public static void main(String[] args) {

walk(5);

System.out.println(power(2, 8));
}

private static void walk(int steps) {

if(steps < 1) return; //base case
System.out.println("You take a step!");
walk(steps - 1); //recursive case
}
private static int factorial(int num) {

if (num < 1) return 1; //base case
return num * factorial(num - 1); //recursive case
}

private static int power(int base, int power) {

if (power < 1) return 1; //base case
return base * power(base, power - 1); //recursive case
}
}

BroCodez
Автор

Bro makes some of the best learning content on YouTube on this topic, truly an S tier content creator

HandsomeGenius
Автор

This helped me understand recursion more clearly than any of the other longer explanations I've seen. I think seeing the walk method compared directly to a for loop made something finally click in my head.

oswallt
Автор

I wish more teachers would be like him. Clear, concise and direct. No need to use over complicated words because your goal is to teach not to make things harder to understand for the student.

jleo_.
Автор

bro because of you, I really liked Java and I can't even believe how things are easy. thank you so much teacher.

kamalkhashoggi
Автор

I love your videos! You make the topics way easier to understand, thanks for making these!

diamondgirly
Автор

Most underrated youtuber! Thanks as always your tutorial always save me if i dont understand something in our lecture.

cosmicevo
Автор

you are genius man . after lot struggle search lot in youTube, finally your video explained everything .Thanks

barath
Автор

not gonna lie i literally understood and wrote a program using recursion in java after the first 29 seconds. you are amazing man thank you.

Pigeony-Pigeon
Автор

That stackoverflow part eas very funny.

adityarajsrivastava
Автор

You content is insanely good. Thank you Bro 😊

chaithdridi
Автор

Brilliant explanation! Would love it if you made an "intermediate" Java tutorial sometime!

fredericoamigo
Автор

You are the best professor I have ever had !

JNDAHAL
Автор

recently youtube suggested your video, a very organized channel, and complete courses.

ShahJahan_NNN
Автор

Your the best learner I can find on programming that have a good course and is pretty good, also theres no price so subscribe to him and like his vid so he can make money, cause he deserves it

crazygames
Автор

Awesome and clear explanation thanks 😊

bernardkaminskibk
Автор

If you want to be really fancy you could do it in one line like this:

public static int fact(int num){
return (num != 0) ? num * fact(num-1) : 1;
}

oguzhantopaloglu
Автор

thank you so much
recursion was like a nightmare to me and i could never understand it
but after this video I could finally understand

moustafadon
Автор

Vietnamese community is getting to know you, thanks bro

HaiVu-izou
Автор

_Here i am on the road again_
_Here i am upon the stage_
_Here i go playing the star again_
_Here i go, Turn the Page_

sanskarsongara