Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:51:01+00:00 2026-06-12T20:51:01+00:00

Would you show me how can we calculate a recursive value? for example the

  • 0

Would you show me how can we calculate a recursive value?

for example the following recursive function:

int rec (int n)
{
    if (n==1) return (1);
    else  
        return (rec(n-1) + rec(n-1));
}

Is there any general clue to solve these type of problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:51:02+00:00Added an answer on June 12, 2026 at 8:51 pm

    Well lets start by writing this as

    int rec (int n)
    {
      if (n==1) return (1);
      else  
        return (2 * rec(n-1));
    }
    

    As a+a = 2a

    Next we see that is multiplying 2 together n-1 times and on the nth time it is returning 1.

    Therefore this is equivalent to 2^(n-1)

    This means that rec(5) = 2^(5-1) = 2^4 = 16

    Note: the form that I have above is also far more efficient than the one you had since I only calculate rec(n-1) rec(n-2) and so on only once (linear recursion). Where as with your function each is calculated exponentially many times (exponential recursion). This means that while my function scales fairly well, yours is basically unusable for anything larger than 100.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I can show the output from this piece
Using jQuery, can you show me the syntax for playing a sound? I would
I can't seem to find anything that would let me to easily show a
I'm unable to transition from index.html to any pages correctly. All transitions would show
I wanted to create a link that would show content before showing a direct
In my webappalication, i would show a popin if the session was inactive during
Someone once showed me a cool IntelliJ Idea plugin that would show all the
A friend asked me for help on building a query that would show how
I wanted to write a Custom Control that would show a family tree... so
I searched the Web and could not find anything that would show me a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.