
Recursion is a powerful technique but it can be quite difficult to understand. This course explains how recursion works in all mainstream programming languages.
How should you use this course to understand recursion?
Download and unzip this archive of sample code
Java programmers may download this archive which contains most of the C sample programs translated into the Java language.
Download this file for information on more books and web sites and any other notes or FAQs on this course.
Some books treat recursion as a puzzle-solving technique. It’s not. It has numerous important, real-world applications.
Let’s begin by taking a look at a very short recursive function.
Here I’ll show how to debug recursive code using Visual Studio
How are local variables affected by recursion?
So how does recursion actually work? This may be the most important lesson in the course!
What is a stack frame and why does it matter?
Let’s use a debugger again to see how the call stack works
Here we look at more examples of recursive functions
Recursive functions work the same way in most languages. To prove that, I’ve translated the last C project into Ruby.
How does a recursively-called function return a value?
Why isn’t the value of a local variable discarded when it is returned by a function?
When you should use iteration or arithmetic rather than recursion?
Let’s calculate a series of Fibonacci numbers!
Let’s compare iteration and recursion when calculating Fibonacci numbers.
Time to look at a common bug.
When the order arguments has a weird side-effect
One of the most serious bugs you may encounter
Stack corruption can happen even without recursion
A closer look at the stack
Summary of stack frames
How to backtrack from and end-node to a root in a tree
How to recurse from a root to all the nodes or ‘branches’ in a tree
Navigating subdirectories on a disk in the C programming language
Navigating subdirectories on a disk in the Ruby programming language
Now try writing your own disk browser
We are at the end of the course. How can you continue studying recursion?
Recursion is a powerful programming technique. A function that calls itself recursively not only saves programming effort and avoids repetition but it can also be used to navigate complex structures such as Trees and Class Hierarchies.
This is an intermediate-to-advanced level course. It is aimed at programmers who can already program confidently in one or more programming languages. It is not appropriate for beginners.
The courses includes numerous short sample programs to show how recursion works. There are samples written in C, Ruby and C#. However, you don’t need to program in those languages to follow this course. Recursion works the same way in all mainstream programming languages. This course explains the theory and the practice of recursion. You can use the techniques that are taught to write recursive functions in whichever language you prefer: C, C#, Java, JavaScript, Python, Basic, Pascal and others. The course is not about any specific language.
This is what you will learn…
What is recursion?
How variables are scoped in recursive functions
How recursive functions return values
The Stack and Stack Frames
Debugging recursive functions
Recursion v Iteration
Stack Corruption, and how to avoid it
Infinite Recursion, and how to avoid it
Recursing Fibonacci Numbers
Recursing a Class Hierarchy
Trees and recursion
Navigating subdirectories recursively
Code samples provided in C, Java, Ruby...