4 Recursion, corecursion, and memoization
In this chapter
- Using recursion and corecursion
- Creating recursive functions
- Using corecursive (tail recursive) functions
- Implementing memoization
Recursive functions are a ubiquitous feature in many programming languages, although those are seldom used in Java. That’s because of the poor implementation of this functionality. Fortunately, Kotlin offers a much better implementation, so that you can use recursion widely.
With recursion, many algorithms are defined recursively. Implementing these algorithms in non-recursive languages consists mainly of translating recursive algorithms into non-recursive ones. Using a language capable of handling recursion not only simplifies coding, but also allows writing ...
Get The Joy of Kotlin 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.