In this chapter, we consider an immensely powerful technique for solving problems: recursion. Recursion involves recognizing that a problem really consists of the same kind of problem, just on a smaller scale. For example, to sort n elements, we can first find the smallest, then sort all the others, and put them after the smallest. This is, in its essence, what selection sort does; we just didn’t explain it in these terms. When we do describe the algorithm like this, the recursive part is that we sort all but the smallest ...
8. Recursion
Get Introduction to Computational Thinking: Problem Solving, Algorithms, Data Structures, and More 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.