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

  • Home
  • SEARCH
  • 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 8661841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:35:43+00:00 2026-06-12T16:35:43+00:00

I am learning JAVA myself and I am learning about memoization now. But i

  • 0

I am learning JAVA myself and I am learning about memoization now. But i am kind of losing my way…

Does anyone has some sample code about how to compute the Combination in Java by using recursion and using memoization to accelerate the algorithm?

Like a way to compute C5,3 = 5*4*3/3*2*1 = 10? but using recursion?

  • 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-12T16:35:45+00:00Added an answer on June 12, 2026 at 4:35 pm

    Lets do it with an example 20 choose 5

    Since 20 choose 5 is defined as 20! / ( 5! * (20-5)! )

    We could use memoization to store those factorial computations so we don’t have to continually re-compute them under our recursion.

    So:

        //STORING FACTORIAL COMPUTATIONS
        private Map<Integer,Long> factorialMap = new HashMap<Integer,Long>();
    
    
        public Long getFactorial(int number) {
    
            //CHECK IF I ALREADY COMPUTED THIS FACTORIAL
            Long val = factorialMap.get(number);
            if(val != null) {
                //GOT IT!
                return val;
            } else {
                //NEED TO COMPUTE!
                val = getFactorialRecursive(number);
                //STORING IT TO SAVE COMPUTATION FOR LATER
                factorialMap.put(number, val);
                return val;
            }
        }
    
        //RECURSIVE FUNCTION TO COMPUTE FACTORIAL
        public Long getFactorialRecursive(int number) {
            if(number < 2) {
                return 1L;
            } else {
                return number * getFactorialRecursive(number-1);
            }
        }
    
    
        //ACTUAL CALL TO "20 choose 5"
        public Long combination(int fromVal, int chooseVal) {
            return getFactorial(fromVal)/(getFactorial(chooseVal)*getFactorial(fromVal-chooseVal));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning Java and find myself sending methods around while asking for help but
I am learning java and started with classes and I am now having some
I'm learning Java on my own; and therefore the code below has no function
I am learning Java with Swing and I have some problems with using JTextField
I'm learning Java, and I know one of the big complaints about newbie programmers
I'm an iPhone/Objective-C newbie with an extensive Java background. I'm learning more about memory
I am learning java myself these days. This function is to calculate the Combination.
I'm learning myself Play 2.0 (Java API used) and would like to have a
I am learning java. Now, it is always a practice in oop to make
When I was learning Java coming from a background of some 20 years of

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.