Introduction to Recursion (Data Structures & Algorithms #6)

  Рет қаралды 665,245

CS Dojo

CS Dojo

6 жыл бұрын

Recursion explained. Java & Python sample code below.
Check out Brilliant.org (brilliant.org/CSDojo/), a website for learning math and computer science concepts through solving problems. First 200 subscribers will get 20% off through the link above.
Special thanks to Brilliant for sponsoring this video.
Find sample code in Python and Java here: www.csdojo.io/recursion
This was #6 of my data structures & algorithms series. You can find the entire series in a playlist here: goo.gl/wy3CWF
You can check out my video about dynamic programming here: • What Is Dynamic Progra...
Also, keep in touch on Facebook: / entercsdojo
If you want to find my introduction to recursion, you can check it out here: • Introduction to Recurs...

Пікірлер: 741
@CSDojo
@CSDojo 6 жыл бұрын
Here's my answer to the frog problem at the end: kzbin.info/www/bejne/a6CQnJegq5x5epI
@supamdeepbains5172
@supamdeepbains5172 6 жыл бұрын
how does function continues to call itself in return statement , im confused because return means stop! please explain bro
@raghavendraprabhu9540
@raghavendraprabhu9540 5 жыл бұрын
Thank you so much.You rock
@andreandrews6237
@andreandrews6237 5 жыл бұрын
I'm late but here goes: yes, the return statement means 'stop', but stop once all code is run and your result is ready. because you're making a function call, your code will return the END of that function call. so it will go as far as the final return and then return the final result AFTER all function calls have been made. so return func(n - 1) will work like this: func(4) -> func(3) -> func(2) -> func(1) and lets just say you have a conditional that says if n
@tuxmusicman
@tuxmusicman 5 жыл бұрын
@@supamdeepbains5172 Return doesn't mean stop. It is used to return values if you have your function set up that way. Many people use it to stop the function in a function that doesn't return anything.
@meghanavaitla7610
@meghanavaitla7610 5 жыл бұрын
I Think the recursion is easy when we know the initial values we are taking and with correct logic
@yukiueda6019
@yukiueda6019 5 жыл бұрын
Recursion is fascinating but it gives me a lot of headaches. Great though.
@alextallen8019
@alextallen8019 3 жыл бұрын
Yeah, I struggle with it and I don't know why
@umar1099
@umar1099 2 жыл бұрын
Mee 2 bro
@sadamth6714
@sadamth6714 2 жыл бұрын
S bro, still i am struggling to understand
@unknownunknown8699
@unknownunknown8699 2 жыл бұрын
they made these algorithms by using the book and now they want us to make better algorithms without the use of books.
@jiakai7254
@jiakai7254 2 жыл бұрын
A good analogy that may help you is Russian dolls. Think of the recursion function as opening a Russian doll only to get smaller dolls after smaller dolls. Soon, you will reach a doll so small you can't open it. That is when the terminal condition is met and the recursion stops.
@ironrose6
@ironrose6 3 жыл бұрын
Great info! The only thing I have to add is that when it comes to fibonacci numbers and you're in an interview scenario, *always* make sure you ask the interviewer where they consider the fibonacci sequence to start. Some consider 0, 1 to be the first two numbers in the sequence, others consider 1, 1 to be the first two numbers. It reflects poorly on you if you make the wrong assumption.
@haydhn1474
@haydhn1474 6 жыл бұрын
by far the best explanation of recursion on youtube!!! Thank you, I was struggling to wrap my head around this, but when you walked through factorial(4) it clicked.
@anthonymit5560
@anthonymit5560 3 жыл бұрын
You should make a video of your understanding.
@magpinybo7524
@magpinybo7524 Жыл бұрын
Same here man
@jinahpark1908
@jinahpark1908 Жыл бұрын
literally the same here, clicked at fact(4) ... a lot of youtubers forget to go backward.. I want to know the CS behind it not just the outcome .
@gabrielle5171
@gabrielle5171 3 жыл бұрын
Even though English isn't my first language, I FINALLY understand a recursion concept by this video. Thank you so much Dojo! You're my favorite teacher on youtube
@CSDojo
@CSDojo 6 жыл бұрын
Hey everyone! In case you’re curious about why 0! = 1, I’d recommend Numberphile’s video about this topic: kzbin.info/www/bejne/g5fOkH9qg91lkKs
@gittysachin
@gittysachin 6 жыл бұрын
Hello YK, please make a video on - "What kind of projects to make to get job at top companies"
@vinayjoshi5712
@vinayjoshi5712 6 жыл бұрын
Please make videos on how to get into big 4 companies. Their interview process and other stuffs.
@glennmiller394
@glennmiller394 6 жыл бұрын
Why not if(n > 0)?
@MartinloveMary
@MartinloveMary 6 жыл бұрын
Glenn Miller if n
@erikvandeven100
@erikvandeven100 3 жыл бұрын
I came up with 144 ways to cross the river: Python: def frogjumps(n): if n > 0 and n < 3: return n if n < 1: return 0 else: return frogjumps(n-2) + frogjumps(n-1) Though it works, I had to try it a few times, cause I cannot really get my head around it yet. But it seemed like the most logical solution and in the end it seemed to work ( I tested it till number 6, which I just did on paper). Would be great to see the more mathematical solution which might make more sense. Definitely going to see the next video.
@apporvaarya
@apporvaarya 5 жыл бұрын
You are my favourite teacher yk.. I had been troubling solving recursion questions..but u cleared its fundamental concepts so well.thanx.
@cnsc8941
@cnsc8941 5 жыл бұрын
Great explaination! I've been struggling with the concept of recursive for a while but your video made it really clear, thank you.
@mrjnutube
@mrjnutube 2 жыл бұрын
Brilliant explanation. I've looked at quite a few videos on recursions, and there are not many teachers who've mastered your level of clarity and simplicity. Your's is truly an art. Keep them coming!
@ankitkumarsingh9815
@ankitkumarsingh9815 5 жыл бұрын
U being a great Teacher ..lots of respect and love from India
@fafza1
@fafza1 3 жыл бұрын
I just want you to know that this is the second video from your channel that my professor has added to online CS course at a public college. I appreciate the way you teach.
@syedabdullahatiq8125
@syedabdullahatiq8125 2 жыл бұрын
what is the prog lang used in this series
@ernestoberger7589
@ernestoberger7589 2 жыл бұрын
@@syedabdullahatiq8125 Java
@biqbicle4982
@biqbicle4982 Жыл бұрын
@@syedabdullahatiq8125 java, python, and c
@melissayamawaki9319
@melissayamawaki9319 5 жыл бұрын
You are a great teacher. Congrats and thank you for helping me understand a bit of recursion!
@rosamarvo
@rosamarvo 2 жыл бұрын
You are the most effective instructor in DS & Algorithms I've listened to so far. Thank you so much!
@amitsinghparihar4627
@amitsinghparihar4627 5 жыл бұрын
This is the best explanation I have seen of recursion after attending a lecture, reading 3 articles, and 4 other videos!! You are awesome dude!! I am freaking subscribing!!
@angeldenilsongilgarcia8309
@angeldenilsongilgarcia8309 3 жыл бұрын
You are brilliant !!!! could not undestand after two hours of class and you clarify everything un 22 minutes !! you are a beast!!
@bernadettealvarado6804
@bernadettealvarado6804 3 жыл бұрын
Not skipping ads to give back to CS Dojo. You're an awesome teacher!
@semperfortis_semperfidelis
@semperfortis_semperfidelis 6 жыл бұрын
Thank you, your videos has awaken the love for programming once more. Greetings from Colombia
@kashifhasnainVTU
@kashifhasnainVTU 5 жыл бұрын
Cs dojo. You are awesome man and the way you explain programming concepts is like anybody can code after watching your sessions... Recursion used to be a nightmare for me.. now the concept is clear.. thanks alot .. kindly bring tutorials for arrays application using example codes
@mariacamilabaronamartinez6748
@mariacamilabaronamartinez6748 3 жыл бұрын
men you're awesome, I not even a English Native and I understand more from you than my courses of Algotihms. Keep going!!!!
@hgjghjkhify
@hgjghjkhify 2 жыл бұрын
Good recursion example showing what happens in the stack with the actual calls of code. I've watched a lot of videos that gloss over the stack call without explaining or showing what happens, so this was incredibly useful. Thank you.
@ahmed_raaphat
@ahmed_raaphat 3 жыл бұрын
The simplest explanation i have ever seen about recursion. Thanks a lot.
@ananthramvijayaraj4554
@ananthramvijayaraj4554 3 жыл бұрын
Man, you are amazing, especially in explaining topics that require a lot of examples to understand. thanks a lot, you just earned a sub!
@timothyhan9735
@timothyhan9735 4 жыл бұрын
Excellent job in explaining recursion by implementing theory with code! Great step-by-step example!
@amitdhawan579
@amitdhawan579 3 жыл бұрын
There are a lot of explanations for recursion but I think yours is probably one of the clearest. Good job bro.
@brainy3429
@brainy3429 3 жыл бұрын
Thanks YK,u r a lifesaver.I was learning abt recursion this afternoon and I don't understand it and I ve been disappointed but now I understand it well.Lots of love and respect 🍁
@kingston_tim7957
@kingston_tim7957 2 жыл бұрын
You are the best teacher I have ever meet, just wanna say thank you Professor Dojo
@emirhankaplan2632
@emirhankaplan2632 3 жыл бұрын
Amazing content! I had trouble getting my mind around Recursion and your videos helped a lot along the way. Thanks a lot!!!
@Qornv
@Qornv 6 жыл бұрын
Hey Dojo, glad you're focusing on higher difficulty topics, there aren't as many that explain as well as you do.
@joMama952
@joMama952 5 жыл бұрын
Great job on this topic. I didn't even need to watch the second half of the video after how well you explained the factorial implementation.
@simoo7755
@simoo7755 5 жыл бұрын
Thank you so much for the great video!Keep them coming!
@aliahed7951
@aliahed7951 4 жыл бұрын
You are an excellent teacher and I finally understand recursion a bit better! Here is my recursion solution for the fibonacci sequence (when you told us to give it a go): def fib(n): if n>=3: return fib(n-1)+fib(n-2) else: return 1 I was so relieved when the code worked as it took me forever to get it right!
@stiksnaki
@stiksnaki 3 жыл бұрын
This is the best Video that I have been seen about recursion.
@thekogrimmer527
@thekogrimmer527 3 жыл бұрын
Amazing teacher and layout compared to other videos. Thanks for this!
@xivus11
@xivus11 2 жыл бұрын
I finally find the problem of my mindset when dealing with recursion. Thank you sooo much!
@cartapo2669
@cartapo2669 6 жыл бұрын
Thanks man. I didn't really understand the CS50 tutorial for recursion so this helped me enough to go back to the CS50 video and totally understand it. Keep it up!
@ArunaKhudan
@ArunaKhudan 3 жыл бұрын
1same here
@DeidaraC5
@DeidaraC5 4 жыл бұрын
I had to watch your videos to finally understand recursion. Please do more videos on basic algorithms and ds, you are a genius!!!! PLEASE!
@TharaMesseroux1
@TharaMesseroux1 2 жыл бұрын
You're so talented! You explain so simply! Thank you so much!
@yiqingzhu8503
@yiqingzhu8503 4 жыл бұрын
Super clean explanation of the flow of recursion
@yigitcanayaz5509
@yigitcanayaz5509 3 жыл бұрын
You're killing it bro!
@anokaggrey3109
@anokaggrey3109 2 жыл бұрын
Best explanation of recursion for me.
@sarthakshah3699
@sarthakshah3699 4 ай бұрын
great explanation and break-down. thank you for this
@pallaviprabhu5265
@pallaviprabhu5265 4 жыл бұрын
Love the way you narrate. Kuddos👏👏
@Pravasith
@Pravasith 2 жыл бұрын
Great content! Love the series
@user-lg2ty6kn6x
@user-lg2ty6kn6x Жыл бұрын
Great explanation!!! Thank you
@amycross5430
@amycross5430 3 жыл бұрын
Dude...you are the greatest...
@simeonveselinski3997
@simeonveselinski3997 3 жыл бұрын
life-saver!Thanks you for the clear explanation!
@ed2023bc
@ed2023bc 7 ай бұрын
Very clear explanation, thank you
@thyiacolt5335
@thyiacolt5335 4 жыл бұрын
DUUUDDEEE THANKU SO MUCH!! It all makes sense now!!
@jasonbelcher4476
@jasonbelcher4476 6 жыл бұрын
wow your teaching style is great! thanks!
@irfancalsr7982
@irfancalsr7982 3 жыл бұрын
I was just thought the way CS Dojo has solved the fibbonacci problem is not the efficientiest way, just then he mentioned about dinamic programming that I hadnt knew. Great, thanks.
@realking4918
@realking4918 3 жыл бұрын
This guy has excellent explanation skills
@potatoitis3326
@potatoitis3326 3 жыл бұрын
Thank you so much. I was struggling so bad with recursion.. this video was so helpful.
@karnaghose4784
@karnaghose4784 7 ай бұрын
Great Explanation
6 жыл бұрын
man, you are amazing, grettings from chile!
@taiwanpix1796
@taiwanpix1796 4 жыл бұрын
very helpful and clear explanation step by step, thanks!
@Dswilsonangel
@Dswilsonangel 3 жыл бұрын
CS Dojo, you are AMAZING!!!!! Thank you SO MUCH for your channel! I am DEFINITELY subscribing!!!! :)
@muhammadkumaylabbas8513
@muhammadkumaylabbas8513 Жыл бұрын
Awesome video thank you very much!
@KM-sf6zy
@KM-sf6zy 4 жыл бұрын
wow what an explanation clear and precise
@limlimminhkhai
@limlimminhkhai 4 жыл бұрын
I love it how did you explain Recursion algorithms :)
@paranoia77
@paranoia77 6 жыл бұрын
thankyou very much for making free lessons, it's very helpful to me, never stop for doing this..
@joro353
@joro353 5 жыл бұрын
Excellent video. Thanks!
@roberthoffmann930
@roberthoffmann930 3 жыл бұрын
Dear CS Dojo, thank you for rescuing my life! many greetings from zurich.
@aminabouzar4416
@aminabouzar4416 3 жыл бұрын
Nice explanation, cleared everything for me!
@mizuhashitsunoka
@mizuhashitsunoka 6 жыл бұрын
Looking forward to tutorials on graphs! It's really difficult to find videos where you like both the way of teaching of the concept, as well as the fast pace of learning. My finals practical will probably be long past by the time a graph video comes up, but it just shows that how much me, and a lot of people probably, will still watch your videos ^^ And if you actually notice this question, then I kinda wanted to ask which of the data structures would you be covering in the future? Would love to watch advanced concepts like heaps and disjoint sets as well.
@ucantseeme1161
@ucantseeme1161 6 жыл бұрын
Hey dojo.... get a series on algorithms....much needed Btw great work!!!!
@xtanion
@xtanion 3 жыл бұрын
solving these problems gives massive satisfaction :) thanks YK .
@jamesv1able
@jamesv1able Жыл бұрын
This was a really helpful video. It was hard to get my head around but this video made it a lot easier. Thanks
@marco.nascimento
@marco.nascimento 5 жыл бұрын
awesome series
@kokowin5851
@kokowin5851 4 жыл бұрын
Thank you soo much... I am a freshman CS student and I don't understand anything my prof is saying. You are videos are really clear and easy to understand. Please make more videos on Data Structures and Algorithms.
@chinemelumj5349
@chinemelumj5349 2 жыл бұрын
Thank you so much, I'm starting to grasp this concept❤.
@duncanmwangi3468
@duncanmwangi3468 10 ай бұрын
Thank you for the good explanation,
@sipp5657
@sipp5657 6 жыл бұрын
Amazing video as usual
@jjola
@jjola Жыл бұрын
this REALLY helped
@maharaniputrisuari8783
@maharaniputrisuari8783 3 жыл бұрын
THANK YOU SO MUCH I'M CLEARLY UNDERSTAND THIS
@ice_cube918
@ice_cube918 4 жыл бұрын
Very helpful!
@paulshekhovtsov7031
@paulshekhovtsov7031 2 жыл бұрын
Thanks, for great explanation!
@mvrius.9
@mvrius.9 2 жыл бұрын
The best video if you want to understand recursion for real!
@hondedtij6761
@hondedtij6761 3 жыл бұрын
Sad part is that these kind of talented people who can make you understand concepts as easily as that are not working on colleges, they are on top companies giving them all their talent.
@cortisol_induced_coma
@cortisol_induced_coma 3 жыл бұрын
To be fair though, those top companies pay them more than many colleges would.
@doomshot7324
@doomshot7324 2 жыл бұрын
yes colleges don't pay well sometimes
@samglick8479
@samglick8479 4 жыл бұрын
very cool video, taught me a lot about recursion
@IPLOFFICIAL-ml4fw
@IPLOFFICIAL-ml4fw 6 жыл бұрын
thanks buddy...You are really hopeful...I am your regular some kind of fan..i am learning python from your video.thanks buddy
@renwarbaxtyar5638
@renwarbaxtyar5638 4 жыл бұрын
i can't imagine what a wonderful teaching you are really better than my teacher .
@brunoavelar4003
@brunoavelar4003 2 жыл бұрын
Thank you -- this helped me.
@randenpatterson297
@randenpatterson297 3 жыл бұрын
YOU my friend are GREAT!!!!!!
@kenanaosithole1586
@kenanaosithole1586 Жыл бұрын
This is really amazing stuff especially for a self learner
@emptyspace2685
@emptyspace2685 3 жыл бұрын
The imagery of recursion in my head is so satisfying. It’s like the computer opening a larger and larger function until it reaches the else statement and then closes it. It’s kinda like that domino thing where they all fall on to each other initially, and then when it hits the end they all fall again
@RajatSingh-rh5hg
@RajatSingh-rh5hg 4 жыл бұрын
even though english is not my native language i can understand ur concepts very easily..tq for ur fabulous explaination
@quermg2543
@quermg2543 2 жыл бұрын
Best video ever
@luistovar6916
@luistovar6916 3 жыл бұрын
I tried to solve the exercise, this was my solution in kotlin: fun fibRec(position: Int):Int { return if(position
@yuliavaiman7626
@yuliavaiman7626 2 жыл бұрын
Thank you for your video 💚
@nijhumpaul9472
@nijhumpaul9472 4 жыл бұрын
Great video. Thank you so much
@hondedtij6761
@hondedtij6761 3 жыл бұрын
Absolute genius!
@syrineayedi3243
@syrineayedi3243 2 жыл бұрын
this video is better than my university teacher thank u man !
@babuldebbarma3395
@babuldebbarma3395 6 жыл бұрын
Very clearly and easiest way explained. It is similar process in loop function if I'm not wrong. Anyway got very clear in recursion:) Thank You and keep going;)
@jamessun6249
@jamessun6249 3 жыл бұрын
Great tutorial! You are awesome.
@graykaufmann
@graykaufmann 3 жыл бұрын
Thank you for your explanation. I think the mathematical explanation in the beginning helped a lot to really understand, what the recursive function really does. I didn't understand, that the function is calling itself till the if statement becomes true.
@TheKapish01
@TheKapish01 6 жыл бұрын
Thanks dojo for helping
@raghuop8675
@raghuop8675 6 жыл бұрын
Thank you so much sir....I'm always waiting for your videos..please don't stop your teaching sir...its my humble request...
@pratyushtripathy2750
@pratyushtripathy2750 6 жыл бұрын
Very cool bro! Keep going.
@Kidpunk98
@Kidpunk98 3 жыл бұрын
Excellent explanation, you are clearly incredibly intelligent and you know how to relay that knowledge as well!
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
small vs big hoop #tiktok
00:12
Анастасия Тарасова
Рет қаралды 27 МЛН
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 97 МЛН
Sigma Girl Past #funny #sigma #viral
00:20
CRAZY GREAPA
Рет қаралды 29 МЛН
What on Earth is Recursion? - Computerphile
9:40
Computerphile
Рет қаралды 740 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 215 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
Introduction to Trees (Data Structures & Algorithms #9)
10:30
What Is Dynamic Programming and How To Use It
14:28
CS Dojo
Рет қаралды 1,5 МЛН
This is a Better Way to Understand Recursion
4:03
Alex Hyett
Рет қаралды 29 М.
Fibonacci Series In Java With Recursion - Full Tutorial (FAST Algorithm)
15:11
5 Problem Solving Tips for Cracking Coding Interview Questions
19:12
small vs big hoop #tiktok
00:12
Анастасия Тарасова
Рет қаралды 27 МЛН