This chapter is about recursion, which is when a function directly or indirectly calls itself. Recursive programming looks as if it should be simple. Indeed, a good recursive solution often has a simple, almost elegant appearance. However, very often the route to that solution is anything but simple. This is because recursion requires us to think differently than we do with other types of programming. When we process data using loops, we’re thinking about processing in a sequential manner, but when we process data using recursion, our normal sequential thinking process won’t help. Many good, fledgling programmers ...

Get Think Like a Programmer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.