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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:32:29+00:00 2026-05-30T06:32:29+00:00

I am learning recursion and having hard time in tracing recursion. Here is my

  • 0

I am learning recursion and having hard time in tracing recursion.
Here is my problem and I have the solution which is working perfectly fine.
I am stuck at some point and not able to proceed with tracing.

problem:
Given an array of ints, is it possible to choose a group of some of the ints, such that the group sums to the given target.

Solution:

public static boolean groupSum1(int start, int[] nums, int target)
      {
          if (start >= nums.length) return (target == 0);             
          if (groupSum1(start + 1, nums, target - nums[start])) return true;              
          if (groupSum1(start + 1, nums, target)) return true;            
          return false;
        }

start = 0 (where we have to start the array)

nums[]={10,8,6} target = 16

Please help me with tracing of the problem?

  • 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-30T06:32:31+00:00Added an answer on May 30, 2026 at 6:32 am

    Start by numbering the lines

      public static boolean groupSum1(int start, int[] nums, int target)
      {
      1.    if (start >= nums.length) return (target == 0);             
      2.    if (groupSum1(start + 1, nums, target - nums[start])) return true;              
      3.    if (groupSum1(start + 1, nums, target)) return true;            
      4.    return false;
      }
    

    Here’s the execution (assuming this is what you are asking for):

    1 call groupSum1(0, {10, 8, 6}, 16)
        1. 0 < 3 next
    2 call groupSum1(1, {10, 8, 6}, 6)
        1. 1 < 3 next
    3 call groupSum1(2, {10, 8, 6}, -2)
        1. 2 < 3 next
    4 call groupSum1(3, {10, 8, 6}, -8)
        1. 3 == 3 return false to call 3      
    back to call 3 in line 2.
    5 call groupSum1(3, {10, 8, 6}, -2)
        1. 3 == 3 return false to call 3
    back to call 3 in line 3.
        return false to call 2
    back to call 2 in line 2.
    6 call groupSum1(2, {10, 8, 6}, 6)
        2 < 3 next
    7 call groupSum1(3, {10, 8, 6}, 0)
        3 == 3 return true to call 6
    back to call 6 in line 2.
        return true to call 2
    back to call 2 in line 3.
        return true to call 1
    back to call 1 in line 2.
        return true
    

    The number in front of the recursive call is just an index I’m using to keep track of depth. I hope it’s understandable.

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

Sidebar

Related Questions

I'm having a great time learning Python, but I've just gotten a bit stuck
I'm learning python for the first time. I have an aim which is to
I'm currently learning algorithms in my spare time but have the following question while
I have 2 solutions to a recursion problem that I need for a function
I am learning about recursion tree's and trying to figure out how the height
For learning and demonstrating, I need a macro which prints its parameter and evaluates
Guys I'm working on class called LINT (large int) for learning purposes, and everything
I write some code to learning F#. Here is a example: let nextPrime list=
I'm learning Python and I have been playing around with packages. I wanted to
Recently, I'm learning F#. I try to solve problem in different ways. Like this:

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.