Why “Inception” reminds us of recursion.
No essential parts of the movie were discussed in this article. However, there are some key concepts or vague scenes mentioned for context, so be aware. We have a zero tolerance for spoilers, the hurt and damage caused by them is too immeasurable (insert a dramatic sight here). But if you’re a fan of the movie, or just want an insight on recursion, this article is definitely inclusive.
The process of movie enjoyment is quite intimate so it might differ from one viewer to another. Some prefer to combine it with a snack, others with the company of a friend. Nonetheless, “Inception” by Christopher Nolan is a masterpiece that shall be experienced in the highest form of concentration. This dynamic dream-sharing film takes the concept of planting an idea into one’s mind on a completely next level. With its action sequences, complex corporate espionage, and the notorious end scene, the focusing requirement is rather crucial.
Well, unless you’re a programmer of course and the entire movie turns into a bizarre déjà vu moment of “I feel like I’ve witnessed this approach before”. And yes, of course you have, you little overworked soul. Its name, Recursion.
The procedure used in ‘Inception’ of having a dream within a dream, is oddly similar to the basic logistic of this programming technique.
In the most basic definition, recursion is a process in which a function calls itself. This allows it to be repeated several times since it calls itself during its execution.
So the approach is quite similar in both cases, the movie and the function: You have one problem, broken down into smaller forms of itself, to find a more efficient solution. One of the aspects of using recursion is that a major part of the solution lies in solving this “smaller” version of the problem – specifically, solving the same one on a simplified or smaller input.
But if the solution to every smaller problem in a recursive algorithm depended on a solution to an even smaller algorithm, it becomes clear that this process would never end. So, to properly handle this recursive issue, a base case is always necessary, where a problem of sufficient simplicity can be solved by itself, without reliance on any other thing being dealt with.
This Base Case is also known as the first part of the function and is what prevents the algorithm from running forever. The second part is more interesting and is known as the Recursive Step.
So we have the Base dream (the first and main one *cough* in the plane *cough*), which in itself consists of other dreams. As we know all our beloved characters, inside the layers of dreams, needed a kick to wake up and get out of a level. If that wasn’t executed according to the plan, the concept of Limbo or unconstructed dream space would come into play. That raw endless subconscious is not just a horrifying experience from the plot, but it’s also what happens in infinite recursion.
Similar to the kicks/triggers the dreamers had to experience, our recursion functions aren’t that different. Every call into the method results in either a base case being triggered or a call to the same method where the parameters are closer to a base case (often called a recursive call). If this doesn’t happen then the program will run forever (LIMBO).
As the analogy of ‘Inception’ itself, this programming method may seem quite overwhelming or confusing at first. But it all comes down to a simple ideology: A base with layers within it.