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 7649309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:55:59+00:00 2026-05-31T10:55:59+00:00

I am preparing for computer science AP exam and have recursions as one of

  • 0

I am preparing for computer science AP exam and have recursions as one of the topics. Being reletively new to programming I wanted to know if there is any easy way, or a few tips you would like to offer regarding recursion. On the exam we have no access to the computer (obviously). So what is an easy way to find solutions to recursions. For example the following is a problem diectly from my book.

public static int mystrey(int x)
{
    if(x == 0)
    {
        return 0;
    } 
    else
    {
        return (x + mystrey(x/10)+mystrey(x/4);
    }
} 

What would be the return value if mystrey(10) is called?

  • 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-05-31T10:56:00+00:00Added an answer on May 31, 2026 at 10:56 am

    Well if you use recursion it’s good to know the meaning of the function. This helps a lot to understand why the method is recursive. Furthermore calculating the function on paper is mostly done by a method called “dispatching”. In this case you see that mystrey(0) = 0 (the if-case).

    If you want to calculate the value of mystrey(10) you know it’s a sum of 10, mystrey(1) and mystrey(2).

    You simply create a table where one can put:

    0: 0
    10: 10+f(1)+f(2)
    

    we now calculate the value of the function with the highest argument so mystrey(2):

    2: 2+f(0)+f(0)
    

    we know the value of f(0), it’s already in the table, so

    2: 2+0+0=2
    

    now we calculate f(1)=1

    We finally conclude that f(10)=10+f(1)+f(2)=10+1+2=13.

    Using a table becomes helpfull when there is a lot of recursion. A lot of times recursion results in overlap, where a huge number of times the function with the same arguments must be computed. With dispatching one can avoid the “branching”. One can see recursion as a tree. Because f(0) has a fixed value this is called the “base case” and are the leafs of the tree. The other function values are called “branches”. When calculating f(10) we need to calculate f(1) and f(2), so one could draw edges from f(10) to f(2) and f(1). And so one could repeat the process.

    Also in most cases a good programmer will program this dispatching in the algorithm. This is of course done by declaring an array an store values in the array and perform a lookup on it.

    In recursion theory it’s common the recursion consist of two parts: a base case part, where answers are “hard coded” for some function calls (in your example when x=0), and a recursive part where f(x) is written in parts of f(y). In general one can use dispatching by building an intial table with the hard coded values, and calculate the value of a specific x by starting to fill in the entry of x in the table, and work down.

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

Sidebar

Related Questions

Right now I'm preparing for my AP Computer Science exam, and I need some
I am preparing for an exam and studying questions. However I have one question
I'm preparing a presentation about JavaScript in different browsers. I know that there are
I'm preparing to go to a computer science contest by completing problems from past
i'm going to install sql server 2008 on my computer,during preparing the installation there
I would like to know how one achieves the following signature. I have read
In preparing to a OOP exam, I enjoyed seeing g++ compile the following code
I am preparing a lecture on files for the more junior students in programming
Preparing for exam and got stuck at this question: Allowed operators are <<,+,& no
While preparing for the SCJP-6 exam I faced with a difficult issue. I can’t

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.