Recursion in Programming - Full Course

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • Recursion is a powerful technique that helps us bridge the gap between complex problems being solved with elegant code. Within this course, we will break down what recursion is, why you would and wouldn’t want to use it and look at a variety of examples for how it can be used.
    We’ll break down recursion with all sorts of data-structures, animations, debugging and call-stack analysis to get a deeper understanding to these principles.
    The code is written in Java, but the principles are agnostic to any language.
    ✏️ This course was developed by The Simple Engineer. Find him online:
    🔗 / thesimpleengineer
    🔗 / thesimpleengineer
    ⭐️ Course Contents ⭐️
    ⌨️ (0:00:00) Introduction
    ⌨️ (0:00:42) What Is Recursion?
    ⌨️ (0:00:50) Explaining Recursion via ATM Analogy
    ⌨️ (0:04:56) Explaining Recursion via Essay Revision Analogy
    ⌨️ (0:06:22) Summarizing What Recursion Is
    ⌨️ (0:07:15) Why & Why Not Recursion
    ⌨️ (0:10:57) Understanding The Call Stack
    ⌨️ (0:11:32) Call Stack Analogy
    ⌨️ (0:16:35) Recursion With Strings Introduction
    ⌨️ (0:16:50) String Reversal Explanation
    ⌨️ (0:20:47) String Reversal Call Stack Animation
    ⌨️ (0:22:59) Palindrome Explanation
    ⌨️ (0:25:46) Palindrome Call Stack Animation
    ⌨️ (0:27:46) Recursion With Numbers
    ⌨️ (0:28:02) Decimal To Binary Explanation
    ⌨️ (0:31:12) Decimal To Binary Code & Debug
    ⌨️ (0:34:33) Sum of Natural Numbers Explanation
    ⌨️ (0:36:17) Sum of Natural Numbers Code & Debug
    ⌨️ (0:38:51) Divide & Conquer Algorithms
    ⌨️ (0:39:27) Binary Search Animation & Explanation
    ⌨️ (0:43:50) Fibonacci Explanation
    ⌨️ (0:45:54) Fibonacci Animation
    ⌨️ (0:49:07) Merge Sort Explanation & Animation
    ⌨️ (0:53:21) Merge Sort Code & Debug
    ⌨️ (1:09:36) Linked Lists
    ⌨️ (1:09:49) Linked List Reversal Animation
    ⌨️ (1:14:48) Linked List Code & Debug
    ⌨️ (1:19:52) Merge Two Sorted Linked Lists Animation
    ⌨️ (1:25:53) Merge Two Sorted Linked Lists Code & Debug
    ⌨️ (1:29:02) Trees
    ⌨️ (1:29:14) Insert Value Into Binary Search Tree Animation
    ⌨️ (1:31:32) Insert Value Into Binary Search Tree Code Walkthrough
    ⌨️ (1:33:43) Insert Value Into Binary Search Tree Call Stack Animation
    ⌨️ (1:35:11) Print All Leaf Nodes Explanation
    ⌨️ (1:37:02) Print All Leaf Nodes Code & Debug
    ⌨️ (1:41:09) Graphs
    ⌨️ (1:41:21) Depth-First Search Animation
    ⌨️ (1:42:58) Depth-First Search Code Walkthrough
    ⌨️ (1:45:38) Recursion Optimizations
    ⌨️ (1:45:44) Memoization & Caching
    ⌨️ (1:47:59) Tail-Call Recursion
    ⌨️ (1:50:48) Conclusion
    🎉 Thanks to our Champion and Sponsor supporters:
    👾 Wong Voon jinq
    👾 hexploitation
    👾 Katia Moran
    👾 BlckPhantom
    👾 Nick Raker
    👾 Otis Morgan
    👾 DeezMaster
    👾 Treehouse
    👾 AppWrite
    --
    Learn to code for free and get a developer job: www.freecodecamp.org
    Read hundreds of articles on programming: freecodecamp.org/news

Komentáře • 603

  • @reapermerc8337
    @reapermerc8337 Před 2 lety +203

    0:00 "When learning about recursion, it can seem like you are going back to the beginning" XDXDXD
    Why is no one talking about this neat pun

  • @polimorphic13
    @polimorphic13 Před rokem +18

    The analogies and snippets of code are truly amazing. Thank you for this course!

  • @snehashishghosh7258
    @snehashishghosh7258 Před 2 lety +74

    The way in which the lecture has been made is awesome... From the smallest of concepts to advanced concepts. I enjoyed learning.

  • @billiamreynolds
    @billiamreynolds Před 2 lety +32

    Man thank you so much for your explanations of how recursive calls work on the call stack, and then also how to interpret the call stack through debugging. This cleared up so much confusion for me!

  • @shankarghimire4492
    @shankarghimire4492 Před 2 lety +12

    Thank you so much Ryan for sharing your knowledge with the world!
    Very amazing content and explanation! :)

  • @michaelcamp2870
    @michaelcamp2870 Před rokem +21

    Around 13:20 is exactly the kind of explanation that I was looking for. I understood how recursion works when a human does it, but not how the computer would handle it. The call stack stuff cleared this up for me. Thank you!

  • @Ericsicons
    @Ericsicons Před rokem +157

    Thanks for the great content! It covers so many different areas of software development.

  • @raghavsharma2762
    @raghavsharma2762 Před 11 měsíci +4

    THERE CANNOT BE A BETTER VIDEO A RECURSION.
    YOU EXPLAINED ALL THE CONCEPTS AND PROBLEMS SO WELL.

  • @best1000
    @best1000 Před rokem +4

    I have watched many videos on Recursion and i can assure you this is the best way that has been explained Recursion so far. Thank you all provided and posted this video here so that million of people can universally learn this.🙏🙏🙏

  • @pravatyadav3623
    @pravatyadav3623 Před 3 lety +39

    Google algo needs to put this video on top when searching for recursion

  • @mylaramvenkatesh9796
    @mylaramvenkatesh9796 Před 2 lety +12

    There are no words to praise you about your explanation and content, Really Mind blowing for me, Super content thank you man

  • @marklord7614
    @marklord7614 Před rokem +84

    This is what the education system needs. Well-put-together courses that are accessible to anyone with a computer. I'm sure you'll continue to get likes and subscriptions well into the future because of this gem. Well done.

  • @raunakmitra7868
    @raunakmitra7868 Před 3 lety +49

    The ATM analogy was very elegant.❤️

  • @xzoldik
    @xzoldik Před 6 měsíci +1

    This the best tutorial of recursion I have ever seen on youtube
    such a great simple explanation really from zero to hero

  • @sanujamethmal9188
    @sanujamethmal9188 Před 3 lety +19

    Thanks a lot. These kind of videos are so rare. Please consider more videos on functional programming design patterns

  • @chewbacca9783
    @chewbacca9783 Před 2 lety +2

    The best Recursion Video available on internet.
    Thanks for making the video.

  • @abdourahman87
    @abdourahman87 Před 2 lety

    Thanks to the simple engineer now that I really understand what recursion is all about. You really made my day today :)

  • @ahmedbello6298
    @ahmedbello6298 Před 2 lety +10

    Thank you so much for the video. This is the best explanation I've got on recursion after several books and CZcams videos. The analogy where people were waiting in a queue (for ATM) is in my view what set my mind free on how to go about recursion. Now I know how and why a problem is attacked recursively.
    Cheers from me!

  • @jasonistheking
    @jasonistheking Před 2 lety +36

    I feel like the first 5 minutes of this video helped me understand recursion better than my CS classes in college. I ended up switching tracks away from CS because I couldn't wrap my head around recursion and trees...

    • @looming_
      @looming_ Před 2 lety +2

      You cannot understand trees or graphs without recursion. It takes some practice, but becomes quite intuitive once you wrap your head around it.

  • @advaithsahasranamam6170
    @advaithsahasranamam6170 Před rokem +3

    This. is.... BEAUTIFUL. ABSOLUTELY BEAUTIFUL LIKE DAMN. Why isn't anyone teaching like this guy?
    Hats off to you!

  • @drewperotti
    @drewperotti Před 2 lety

    Thanks for the vid, I've had a hard time with recursion and this is really helping.

  • @akmzahidulislam2764
    @akmzahidulislam2764 Před 2 lety

    Just wonderful! A brilliant teacher who is wholeheartedly passionate and industrious about teaching. Result? You watch this.

  • @vikramc08
    @vikramc08 Před rokem

    Thanks a lot for your effort! It is really helpful video. And I can see how with great patience, you explain recursion on different topics. Thanks again!!

  • @millsdickson8498
    @millsdickson8498 Před rokem

    Wow, recursion...done! Thank you so much for this very excellent presentation! I now have a solid foundation on this matter.

  • @pabloescaida6205
    @pabloescaida6205 Před rokem

    Awesome! Thank you so much for the course !😀

  • @e28makaveli
    @e28makaveli Před rokem

    Good stuff! Very clear and concise. Thank you.

  • @ADITYA-fk1zy
    @ADITYA-fk1zy Před 2 lety

    using relative analogies and debugger to explain call stuck made it easy for me understand,Thanks simple Engineer

  • @caiocutrim3596
    @caiocutrim3596 Před rokem +1

    what's up guys?
    This content is amazing, I'm really impressed with the simplified approach.
    I'm learning a lot.

  • @carloslazarin
    @carloslazarin Před 2 lety

    Thanks for the content presentend here; very clear, excellent explanation very great examples!

  • @atharvpal7038
    @atharvpal7038 Před 5 měsíci

    One of the best lectures I have ever seen. Thank you very much!

  • @Moses_coder
    @Moses_coder Před rokem

    Good work, simplifies what seems to be complex stuff

  • @davidwalker6960
    @davidwalker6960 Před 2 lety +5

    Excellent. Recursion has always been a mental twister for me. Trying to master it now, to make it a normal part of my thought processes when developing. Very informative, easy to follow. Thanks!

  • @satestactmathtutor6570

    i enjoyed how you show the stacks and did alot of examples.. big big thanks from Egypt

  • @gigachad400
    @gigachad400 Před 3 lety +1

    Best video on recursion!!

  • @yungxix6343
    @yungxix6343 Před 3 lety +1

    Thanks for putting this out

  • @noelhdez3640
    @noelhdez3640 Před 3 lety +1

    Broooooo. Literally you read my mind!!

  • @evachild
    @evachild Před 2 lety

    Great refresher for interview practice!

  • @galibmahim9544
    @galibmahim9544 Před rokem +1

    Very nicely explained. Well for me The ATM example quite describes in on itself what recursion is then the stack memory that computer has explains why it works like last task to the first.
    Again very good. Appreciate❤

  • @slurpeesauce1750
    @slurpeesauce1750 Před 2 lety +1

    Makes programming way more fun thank you

  • @SaschaRobitzki
    @SaschaRobitzki Před rokem +1

    Great course! Following along in C++ and it works very well.

  • @servantofthelord8147
    @servantofthelord8147 Před 6 měsíci

    This video explained the call stack excellently! Recursion is one of those things I just assumed "oh, it's difficult so nobody really get's it other than theoretical researchers, so I don't need to really close that knowledge gap, but in fact this video showed me it didn't need to be so difficult. Great job!

  • @headfullofcode
    @headfullofcode Před rokem

    Well designed content, thanks mate :)

  • @F.R.A.N.K.I.E
    @F.R.A.N.K.I.E Před 2 lety +2

    This is such a comprehensive course. I understood recursion better than i ever thought I would. THANK YOU!

  • @manojalayer
    @manojalayer Před 2 lety

    Well designed, well presented
    Super Helpful
    Thank you

  • @james3742
    @james3742 Před rokem

    This is amazing. Thank you!

  • @joel.osei-asamoah
    @joel.osei-asamoah Před 2 lety

    Great video, helped a lot!

  • @iiimiiim
    @iiimiiim Před rokem

    I love the ATM example. Thanks!

  • @mrbadmanzaman
    @mrbadmanzaman Před 2 lety +2

    Great video, helps explain recursion clearly using good examples and diagrams. I use it to help teach recursion in my A level CS classes. I recommend trying to implement the examples in code (I used Python) to help better understand the examples. The instructor also uses a good clear tone of voice with the right amount of pace so it is easy to follow the explanations.

  • @prasunkumar1434
    @prasunkumar1434 Před 3 lety +5

    Every time I am in search for a topic, FCC comes with a video. Thank You FCC for your efforts.

  • @abudujana2244
    @abudujana2244 Před 2 lety

    Thanks for this, really appreciate it.

  • @ssheking
    @ssheking Před rokem

    Very clear. Thanks!

  • @servantofthelord8147
    @servantofthelord8147 Před 6 měsíci

    WOAH! The ATM ANALOGY WAS EVERYTHING FOR ME! I wish I saw this when I first started learning about recursion, hahaha, thank you very much!

  • @aarondiaz2506
    @aarondiaz2506 Před 10 měsíci

    No words, thank you, can't ask for a better teacher🙌

  • @RahulSharma-lw2ss
    @RahulSharma-lw2ss Před rokem

    Best ever video for entire recursion concept

  • @sig7813
    @sig7813 Před 2 lety

    So well explained. Thank you

  • @ketanmuttha1066
    @ketanmuttha1066 Před 2 lety

    Awesome video. Learnt a lot

  • @jmbrjmbr2397
    @jmbrjmbr2397 Před 5 měsíci

    I have already commented but I want to comment again.. How good is this lecture? It's unbelievable. Thank you so much great people, I love you so much

  • @MianyunNi
    @MianyunNi Před 5 měsíci

    Thank you so much for doing this! Best video ever!~

  • @kd6164
    @kd6164 Před 3 lety +1

    Extremely valuable, and awesome video; thanks for the great content The Simple Engineer!!!

  • @psppoks
    @psppoks Před 3 lety

    Thank's Now I Understand Recursion Thanks @The Simple Engineer

  • @nidhalmejai346
    @nidhalmejai346 Před 2 měsíci

    the examples with which you explain and visualize the call stack was the most important part in this tutorial i think the call stack was the part we all missed when learning about recursion and you just explained it carefully and clearly thank you for the efforts you have put in this video.

  • @nzendereya6914
    @nzendereya6914 Před 3 lety +1

    Thank you so much free code camp.

  • @havefun5519
    @havefun5519 Před rokem

    Thanks for the great detail tut.

  • @perezshealtiel7011
    @perezshealtiel7011 Před 2 lety

    Very nice illustrations. Thank you.

  • @jmbrjmbr2397
    @jmbrjmbr2397 Před 5 měsíci

    This is an extremely high quality, precious video. I haven't studied cs in uni, but I highly doubt the education is this high quality there.

  • @shukrulloabduqodirov4353
    @shukrulloabduqodirov4353 Před 6 měsíci

    Aynan Uzbda yetishmayotgan proekt bolibdi. Omadilarni bersin! Alloh adashtirmasin. Ohirigacha hayrli haloli bo'lsin!!!

  • @rhodabaruch4
    @rhodabaruch4 Před rokem

    Thank you, Ryan!

  • @yagan_dawn2008
    @yagan_dawn2008 Před rokem

    What a great tutorial!

  • @sret919
    @sret919 Před 5 měsíci

    This is an icredibly high quality and valuable, precious video. I love internet, I love youtube, I love these nice people teaching with this much quality

  • @enmanuelsanchezabarua5482

    Very clear explained 👏🏽

  • @animemotivationx
    @animemotivationx Před 2 lety +11

    In the beginning when I started learning programming I didn't think recursion is that much important but when I started to learn DSA. I figured it out recursion is the soul of DSA and now I am learning, I have crossed 1:30 hr video and it has been so much fun and easy to grab. The tutor is really good ...

    • @Codenames560
      @Codenames560 Před 2 lety +3

      Agreed man, the worst thing I've done was trying to attempt tree, graph and linkedlist problems without a complete understanding of recursion.

    • @ru2979
      @ru2979 Před rokem

      1:30:00

  • @RyanScarbrough
    @RyanScarbrough Před rokem

    Epic intro, can already tell it's a goodone!

  • @yoursamrit2000
    @yoursamrit2000 Před 3 lety +20

    First, I've always wanted to know about this. And here you are!!

  • @SumanPokhrel0
    @SumanPokhrel0 Před 3 lety +5

    I am just starting DSA , and u just dropped a gem , thank you so much 🤟🤟

  • @idc20627
    @idc20627 Před rokem +4

    Im surprised factorial wasn't amongst one of the examples. This resource plus the MIT lecture on youtube regarding recursion has cemented this tool for. On to the next tool!

    • @Shil131
      @Shil131 Před rokem

      will you be able to share the mit lecture video link?

  • @bac9982
    @bac9982 Před 2 lety +8

    Like many other comments, the simplistic breakdowns of recursion in this video help make sense of this topic for even the most confused. I thoroughly enjoyed this video and wish this could get bumped up for more of the world to see!

  • @madhubalajayakumaran9340

    Thanks Ryan and FreeCodeCamp for this!!

  • @ridhamsuhagiya4886
    @ridhamsuhagiya4886 Před 3 lety

    wow lovely course !!!

  • @chhavimanichoubey9437
    @chhavimanichoubey9437 Před 2 lety +1

    yes this fucking video was needed by many people like me who still doesn't understand recursion and have no idea how to contemplate this.

  • @tirupatirao7521
    @tirupatirao7521 Před 2 lety

    This is simple and crystal clear to start with. Dn,t underestimate as it is long video.it’s 200% wort

  • @theamatuer9097
    @theamatuer9097 Před 2 lety +2

    What a video! This is much easier to understand than the CS course I'm taking. Thank you, The Simple Engineer.

  • @jasmine9538
    @jasmine9538 Před rokem

    It took me about 5 replays to for the linked list reversal to click. But when I had my "ah ha" moment... chef's kiss! 😚Amazing!

  • @sherazdotnet
    @sherazdotnet Před 2 lety

    Great great beginning of video. Very nice explanation of what recursion is and how to think in recursion. Liked how the code is explained using graphics which helps understand what the code is doing. But, it'd have been great if no code was displayed for any given problem first and discuss what can we do to solve the problem. That's what's the most challenging part. Take Merging Sorted Link List example. The code was shows right away and we are walked through what the code is doing. I think more interesting part would have been to discuss the approach and then come up with a solution.
    But I must say that this video so far is the best in explaining Recursion.

  • @arunvishwakarma2779
    @arunvishwakarma2779 Před 10 měsíci

    Thanks a lot for this :)

  • @mrboyban
    @mrboyban Před 2 lety +1

    Well done mate! Better than a so called "UK Top University"

  • @Archius_09
    @Archius_09 Před 3 lety +394

    I sometimes feel guilty as i dont pay any fees to them and yet dont have time to study all this things :(

    • @girlgotTECH
      @girlgotTECH Před 3 lety +23

      You are the voice of my soul

    • @utkarshkukreti239
      @utkarshkukreti239 Před 3 lety +24

      You have to study in order to get the skill and then earn from your skill then you can pay and don't feel guilty.

    • @Archius_09
      @Archius_09 Před 3 lety +4

      @@utkarshkukreti239 i am a student and my education comes first of all

    • @djay00009
      @djay00009 Před 3 lety +2

      Don't lie. I know newton's a genius

    • @ferhatbeztout1447
      @ferhatbeztout1447 Před 2 lety +1

      Isaac Newton what're you doing in the 21th century ?

  • @paragnaik9826
    @paragnaik9826 Před 3 lety +2

    Much needed

  • @zx5939
    @zx5939 Před 2 lety

    BEST LECTURE EVER!!

  • @eclecticspirit4803
    @eclecticspirit4803 Před měsícem

    best video to understand recursion

  • @reo4465
    @reo4465 Před 2 lety +2

    This is really a very nice explanation. Thank you for making this video.

  • @haruka3203
    @haruka3203 Před rokem +14

    I am mind blown. I almost never use recursion because it felt so alien to me, I've done everything in for loops, while loops, etc, but mostly for loops.
    I've never seen so little lines of code typed for something very very complex! This makes me rethink how I program. Rather than seeing what's in front of me, but taking a step back, identifying a pattern, using that pattern flow to your advantage, adjust the course of the river and viola you've done it.

    • @sret919
      @sret919 Před 6 měsíci

      I guess functional programming works like that. Bartozs Milewski was talking about what you are describing here, it reminded me that.

  • @SylvainBrunerie
    @SylvainBrunerie Před 2 lety +7

    All these examples look super interesting, but I just want to point out that tail-call recursion optimization is super important to know, even though it’s kinda briefly mentioned here. Really sad that’s it’s mostly not supported in JS yet. Have a look at Elm if you want to safely use recursion in the browser :)

  • @orenli7002
    @orenli7002 Před 2 lety

    Great video!

  • @muktarsayeed9198
    @muktarsayeed9198 Před rokem

    Fantastic!!👍👍👍👍

  • @HuzaifaMuhammadSIddique
    @HuzaifaMuhammadSIddique Před 5 měsíci

    I love the 3rd con. It's so true!

  • @ankitshrivastava3672
    @ankitshrivastava3672 Před 3 lety +12

    what a timing, I am just finishing the last section of freecodecamp js DSand Algo certification and I feel like there should be a separate section on recursion, here it is...thanks a lot

  • @supersaiyan-goku-san
    @supersaiyan-goku-san Před 3 lety +2

    The explanation is elegant and awesome! Top notch work

  • @alkhiljohn7640
    @alkhiljohn7640 Před 2 lety

    These guys deserve an award :)

  • @saalim24
    @saalim24 Před rokem +1

    Thank you!

  • @AlancRodriguez
    @AlancRodriguez Před 2 lety

    Great Content!!