Тёмный

Introduction to Recursion (Data Structures & Algorithms #6) 

CS Dojo
Подписаться 1,9 млн
Просмотров 665 тыс.
50% 1

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...

Опубликовано:

 

15 апр 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 741   
@CSDojo
@CSDojo 6 лет назад
Here's my answer to the frog problem at the end: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5o-kdjv7FD0.html
@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 4 года назад
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
@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!
@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.
@CSDojo
@CSDojo 6 лет назад
Hey everyone! In case you’re curious about why 0! = 1, I’d recommend Numberphile’s video about this topic: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Mfk_L4Nx2ZI.html
@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
@ankitkumarsingh9815
@ankitkumarsingh9815 5 лет назад
U being a great Teacher ..lots of respect and love from India
@melissayamawaki9319
@melissayamawaki9319 5 лет назад
You are a great teacher. Congrats and thank you for helping me understand a bit of recursion!
@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!!
@rosamarvo
@rosamarvo 2 года назад
You are the most effective instructor in DS & Algorithms I've listened to so far. Thank you so much!
@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
@semperfortis_semperfidelis
@semperfortis_semperfidelis 6 лет назад
Thank you, your videos has awaken the love for programming once more. Greetings from Colombia
@timothyhan9735
@timothyhan9735 4 года назад
Excellent job in explaining recursion by implementing theory with code! Great step-by-step example!
@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!!!!
@bernadettealvarado6804
@bernadettealvarado6804 3 года назад
Not skipping ads to give back to CS Dojo. You're an awesome teacher!
@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!
@ahmed_raaphat
@ahmed_raaphat 3 года назад
The simplest explanation i have ever seen about recursion. Thanks a lot.
@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.
@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.
@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!!
@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!!!
@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 🍁
@thekogrimmer527
@thekogrimmer527 3 года назад
Amazing teacher and layout compared to other videos. Thanks for this!
@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.
@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!
@kingston_tim7957
@kingston_tim7957 2 года назад
You are the best teacher I have ever meet, just wanna say thank you Professor Dojo
@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!
@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
@xivus11
@xivus11 2 года назад
I finally find the problem of my mindset when dealing with recursion. Thank you sooo much!
@simoo7755
@simoo7755 5 лет назад
Thank you so much for the great video!Keep them coming!
@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.
@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
@stiksnaki
@stiksnaki 3 года назад
This is the best Video that I have been seen about recursion.
@pallaviprabhu5265
@pallaviprabhu5265 4 года назад
Love the way you narrate. Kuddos👏👏
@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
@ucantseeme1161
@ucantseeme1161 6 лет назад
Hey dojo.... get a series on algorithms....much needed Btw great work!!!!
@potatoitis3326
@potatoitis3326 3 года назад
Thank you so much. I was struggling so bad with recursion.. this video was so helpful.
@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.
@anokaggrey3109
@anokaggrey3109 2 года назад
Best explanation of recursion for me.
@paranoia77
@paranoia77 6 лет назад
thankyou very much for making free lessons, it's very helpful to me, never stop for doing this..
@limlimminhkhai
@limlimminhkhai 4 года назад
I love it how did you explain Recursion algorithms :)
@yigitcanayaz5509
@yigitcanayaz5509 3 года назад
You're killing it bro!
@sarthakshah3699
@sarthakshah3699 4 месяца назад
great explanation and break-down. thank you for this
@simeonveselinski3997
@simeonveselinski3997 3 года назад
life-saver!Thanks you for the clear explanation!
@taiwanpix1796
@taiwanpix1796 4 года назад
very helpful and clear explanation step by step, thanks!
@jasonbelcher4476
@jasonbelcher4476 5 лет назад
wow your teaching style is great! thanks!
@Dswilsonangel
@Dswilsonangel 3 года назад
CS Dojo, you are AMAZING!!!!! Thank you SO MUCH for your channel! I am DEFINITELY subscribing!!!! :)
@roberthoffmann930
@roberthoffmann930 3 года назад
Dear CS Dojo, thank you for rescuing my life! many greetings from zurich.
@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
@KM-sf6zy
@KM-sf6zy 4 года назад
wow what an explanation clear and precise
@realking4918
@realking4918 3 года назад
This guy has excellent explanation skills
@aminabouzar4416
@aminabouzar4416 3 года назад
Nice explanation, cleared everything for me!
6 лет назад
man, you are amazing, grettings from chile!
@thyiacolt5335
@thyiacolt5335 4 года назад
DUUUDDEEE THANKU SO MUCH!! It all makes sense now!!
@Pravasith
@Pravasith 2 года назад
Great content! Love the series
@ed2023bc
@ed2023bc 6 месяцев назад
Very clear explanation, thank you
@marco.nascimento
@marco.nascimento 5 лет назад
awesome series
@xtanion
@xtanion 3 года назад
solving these problems gives massive satisfaction :) thanks YK .
@ganeshbobade4591
@ganeshbobade4591 6 лет назад
# Fibonacci Series for Python x, y = 0, 1 for i in range(0, 10): print(x) x, y = y, x + y
@pratapkumarsahu8717
@pratapkumarsahu8717 3 года назад
Thank you I am a begginer man I only know pythona
@chrisarmas8213
@chrisarmas8213 2 года назад
hi, i'm also a beginner, but here are my thoughts about this code: - this prints a sequence that leads to 34 while the resulting fibonacci number for 10 is 55. - i think it should be x,y = 1,1 to arrive at the correct fibonacci number (though this will print the sequence starting with 1 instead of 0). But if we don't want to omit "0" at the beginning, then add 1 to the stop parameter of range() like this: for i in range(0, 10 + 1) sorry, uhhm, correct me if I'm wrong. I'm very willing to learn.
@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;)
@joro353
@joro353 5 лет назад
Excellent video. Thanks!
@amycross5430
@amycross5430 3 года назад
Dude...you are the greatest...
@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...
@user-lg2ty6kn6x
@user-lg2ty6kn6x Год назад
Great explanation!!! Thank you
@chinemelumj5349
@chinemelumj5349 2 года назад
Thank you so much, I'm starting to grasp this concept❤.
@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.
@Kidpunk98
@Kidpunk98 3 года назад
Excellent explanation, you are clearly incredibly intelligent and you know how to relay that knowledge as well!
@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
@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.
@mvrius.9
@mvrius.9 2 года назад
The best video if you want to understand recursion for real!
@samglick8479
@samglick8479 4 года назад
very cool video, taught me a lot about recursion
@maharaniputrisuari8783
@maharaniputrisuari8783 3 года назад
THANK YOU SO MUCH I'M CLEARLY UNDERSTAND THIS
@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
@karnaghose4784
@karnaghose4784 7 месяцев назад
Great Explanation
@renwarbaxtyar5638
@renwarbaxtyar5638 4 года назад
i can't imagine what a wonderful teaching you are really better than my teacher .
@bluebee9670
@bluebee9670 5 лет назад
Thank you for showing how to break down the problem :)
@sipp5657
@sipp5657 6 лет назад
Amazing video as usual
@mengwang6936
@mengwang6936 5 лет назад
JESUS! This is the first time that i can code fibbonacci within 10 seconds! Thanks man!
@kenanaosithole1586
@kenanaosithole1586 Год назад
This is really amazing stuff especially for a self learner
@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
@duncanmwangi3468
@duncanmwangi3468 10 месяцев назад
Thank you for the good explanation,
@muhammadkumaylabbas8513
@muhammadkumaylabbas8513 Год назад
Awesome video thank you very much!
@paulshekhovtsov7031
@paulshekhovtsov7031 2 года назад
Thanks, for great explanation!
@luistovar6916
@luistovar6916 3 года назад
I tried to solve the exercise, this was my solution in kotlin: fun fibRec(position: Int):Int { return if(position
@pratyushtripathy2750
@pratyushtripathy2750 6 лет назад
Very cool bro! Keep going.
@chandraprakashsingh2530
@chandraprakashsingh2530 5 лет назад
Nicely taught brother it was very clear to me thanks
@hondedtij6761
@hondedtij6761 3 года назад
Absolute genius!
@bhaskarjyotidas6619
@bhaskarjyotidas6619 6 лет назад
Sir... Please continue this series in detailed. For explaining some data structure examples my preference for the language used is to be JAVA .
@SwaroopSahu
@SwaroopSahu 6 лет назад
Hi Dojo. I really liked your all lectures but I wanted to know that which software are you using for teaching?
@aminuabdusalam3086
@aminuabdusalam3086 4 года назад
What's the hint in a problem that tells you that you'd need to use recursion? Thank you! CS Dojo. Love your style of teaching
@sajeesyed3384
@sajeesyed3384 2 года назад
a great example of how recursion works programmatically, it solved it in my head though
@nijhumpaul9472
@nijhumpaul9472 4 года назад
Great video. Thank you so much
@dont750
@dont750 Год назад
Fun fact: using recursion to solve Fibonacci sequence is actually more inefficient than looping because u are effectively calling the method twice each call and it creates this tree effect.
@ithinkthereforeitalk935
@ithinkthereforeitalk935 Год назад
Memoization is the answer.
@06nishant
@06nishant 3 месяца назад
Use decorater lru_cache
Далее
5 Simple Steps for Solving Any Recursive Problem
21:03
Programming Loops vs Recursion - Computerphile
12:32
Просмотров 1,4 млн
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 209 тыс.
What Is Dynamic Programming and How To Use It
14:28
Просмотров 1,5 млн
Introduction to Trees (Data Structures & Algorithms #9)
10:30
Top 7 Data Structures for Interviews Explained SIMPLY
13:02
What on Earth is Recursion? - Computerphile
9:40
Просмотров 740 тыс.
This is a Better Way to Understand Recursion
4:03
Просмотров 29 тыс.