Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Tail Recursive Functions#

Sumit Rawal answered on May 23, 2023 Popularity 6/10 Helpfulness 1/10

Contents


More Related Answers

  • bash recursive functions
  • Tail Recursion
  • how to make recursive function
  • Recursive Functions
  • tail recursion
  • which of the following algorithm would be best suited for a tail recursive implementation
  • Challenge: Tail Recursion
  • What is tail recursion optimization?
  • Convert a function to a tail recursive function in scala
  • recursive function
  • working of a recursive function
  • Factorial tail recursion

  • Tail Recursive Functions#

    0

    Tail recursive functions are iterative processes and are the functional form of a loop. They are an optimized version of recursive functions, as they allow the function’s stack frame to be reused.

    Stacks are data structures which work like a stack of boxes. Each time a function calls itself, it adds another box or stack frame to the stack. When we add too many boxes to our stack, they fall down. In the same way, when a function makes a large number of recursive calls, the stack overflows.

    If the last action of a function consists of calling a function (like a tail recursive function), one stack frame would be sufficient for both functions. Using a lesser number of stacks or a lesser number of stack frames will prevent a stack from overflowing.

    A Comparison

    Let’s look at the evaluation of both a recursive function and a tail recursive function to better understand how they differ.

    A Simple Recursive Call

    The factorial function we defined in a previous lesson uses a simple recursive call.

    Popularity 6/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala tail
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.