Tail Recursion – SCALA

This is a two part series on Recursion, please complete part-1 before you proceed further.

Why do we need a Tail-Recursive functions?

Simple recursion creates a series of stack frames, and for algorithms that require
deep levels of recursion, this creates a StackOverflowError.

How to Overcome this?

Continue reading

Recursion – SCALA

What is a recursive function?

A recursive function is a function that calls itself.

Why do we need to write recursive functions?

The short answer is that algorithms that use for (or any) loops require the use of var fields, and as you know that pure functions should not use any variable fields. so to write a pure function one should use recursive function.

Visualizing lists

listmonster

Continue reading