Tail Recursion

RECURSION / TAIL RECURSION IN SCALA

Reading Time: 3 minutes Recursion Recursion is a function which calls itself over and over again until an exit condition is met. It breaks down a large problem into a smaller problem, solves the smaller parts, and combines them to produce a solution. Recursion could be applied to many common problems, which can be solved using loops, for and while. Why Recursion? 1. The code is simpler and shorter Continue Reading

Scala Beginner Series (3) : Functional Scala

Reading Time: 4 minutes This series is all about the taste of Scala.It is best suitable for all the newbies in Scala. You may also like: Scala Beginner Series (1) : BasicsScala Beginner Series (2) : Object Oriented Scala In the previous part, we covered the: Classes, constructors, inheritance, and abstract classes Traits and anonymous classes Singleton objects and companion objects Case classes and case objects This article will cover the functional Continue Reading

Tail Recursion in JAVA 8

Reading Time: 3 minutes A tail-recursive function is just a function whose very the last action is a call to itself. Tail-Call Optimisation(TCO) lets us convert regular recursive calls into tail calls to make recursions practical for large inputs, which was earlier leading to stack overflow error in normal recursion scenario. With Scala, making a tail recursive function is easy. The Scala compiler detects tail recursion and replaces it with Continue Reading

Jump Higher With Trampoline

Reading Time: 6 minutes In our earlier blog The Tale of ‘Tail Recursion’, we have talked about tail recursion. And In this blog, we will be talking about limitation of tail recursion and its solution in scala. Unfortunately JVM doesn’t support tail call optimization, but scala does as we have seen. However, what if we are not doing simple tail recursion like we usually do. What if on the Continue Reading

The Tale of ‘Tail Recursion’

Reading Time: 3 minutes Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem (as opposed to iteration). Recursions are really cool and they are highly expressive. For example consider factorial function: But if i increase the size of input, code will blow up. Recursions don’t scale very well for large input sizes. And in practical Continue Reading