people love to joke about recursion as the saying goes in order to understand recursion one must first understand recursion you will see recursion mentioned on Twitter threads and Reddit comments and if you search for recursion on Google even they make a joke of it by adding did you mean recursion at the top of the search results even though these are funny they don't explain recursion very well or why we use it after at level recursion is a function that calls itself but there's more to it than that the point of recursion isn't just to call itself over and over again in an infinite Loop if you do that you'll just get a stack Overflow exception recursion is more like the film Inception if you haven't watched Inception before or you don't remember what happens I'll give you a quick recap don't worry I won't include any spoilers in case you haven't watched it yet John Cobb AKA Leonardo DiCaprio makes his living by doing corporate Espionage instead of spying he steals the information from people's subconscious while they are dreaming then you break in and still in the film a guy called Sato hires Cobb and offers him the chance to wipe his criminal record clean if he can implant the idea of dissolving a company in the mind of one of his competitors to be able to implant an idea into someone's subconscious it isn't good enough to go into just one dream he has to go several layers deep so a dream inside a dream inside a dream in order to wake someone up from the dream world they need a kick a sudden jolt that will wake them up they also have to be mindful of not going too deep otherwise they'll enter what they call limbo a dream realm where anything is possible and you can experience a year in the space of four minutes in the real world so where am I going with all this well a recursive function is like a dream it can call itself in the same way that you can enter a dream inside a dream in your recursive function you always have an exit condition which is like your kick that takes you back up to the calling function without this kick the exit condition you'll keep going into deeper and deeper levels of recursion and eventually enter limbo which in our case is met with a stack Overflow exception if you still have lots of questions about recursion like the final scene in Inception then let's see how we can use it recursive functions are mostly used for navigating tree-like structures like the folder structure on your computer each folder can contain other folders which contain more folders but eventually you'll get down to a folder that just contains files then you have to navigate your way back up the folder structure to get where you started the same structure can be seen in common threads on YouTube videos or blog posts I will be very disappointed if normal leaves a recursion thread in the comments so please leave a comment below any place that has an unknown number of nested elements can use recursion to navigate through them for example I have used recursion for parsing logical Expressions that contain brackets that then contain more Expressions that need to be passed a common example of recursion is calculating the Fibonacci sequence the sequence starts with 0 and 1 and then the following numbers are calculated by adding up the previous two numbers so let's say we want to calculate the tenth number in the Fibonacci sequence to do that we can use a recursive function like this one in this case n starts from zero so we need to put in 9 to get the 10th number in the Fibonacci sequence to work out the tenth number we need to add up the previous two numbers but of course we don't know what they are so we need to call the recursive function again twice in order to work them out this happens again and again until we get to zero or one where we finally return a number and then we work our way back up the cool stack to get the final result of 34. recursive functions are useful and you get a nice simple code but they're not the most efficient way of doing things for each call we have to push and pop methods from the cool stack which often results in poor performance in the Fibonacci code we also end up calling the function with the same number multiple times which isn't very efficient in this case you would actually get better performance by doing it in a loop instead of using recursion especially as we get to higher numbers as with all things in programming it's important that you pick the right tool for the job and now that you know recursion that's one more tool that you can use if you like this video then you might also like my newsletter the Curious engineer where I cover topics to help you succeed as a software developer there is a link in the description if you want to check it out thank you for watching don't forget to go and watch Inception and I will hopefully see you in the next video foreign