6SOLVING PROBLEMS WITH RECURSION

image

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.