What do you understand by tail recursion in Scala ?

devquora
devquora

Posted On: Feb 22, 2018

 

The programmers face various situations where they need to write codes which are recursive in nature. But when we use the recursive functions, we may face a problem in which the function may eat up all the stack space. So, to overcome this problem, Scala provides this particular feature of tail recursion which optimizes the recursive function. After optimization, these functions do not create a new stack space, instead uses the current function stack space. “@annotation.tailrec” annotation has to be used before defining the function and for the last statement, recursive call can be used. After all this, your function will be compiled successfully or else it will give an error.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Scala Interview Questions

    What do you mean by a Scala map?

    The collection of key-value pairs where the key can retrieve the values present in a map is known as a scala map. The k..

    Scala Interview Questions

    List the advantages of using scala over other functional programming languages.

    Some of the advantages due to which scala is preferred over other functional programming languages are listed below: As..

    Scala Interview Questions

    Tell the advantages of companion objects when used in Scala?

    Instead of having static methods or variables, scala has singleton or companion objects. These objects are then compile..