Wrapping Up
The power of recursion is sadly not usable for large-sized problems due to potential stack overflow error. Kotlin provides tailrec to perform tail call optimization on specially written recursions. By converting the recursion into iteration under the hood, the language provides the capability for you to enjoy the power of recursion without suffering the consequences of stack overflow. And, even though the language doesn’t directly provide a memoization function, using the features of the language, we can build the ability to elegantly memoize or cache results of computations. By using this approach, we can greatly reduce the computation time of programs that make use of the algorithmic technique called dynamic programming. We’ve seen ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access