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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:33:42+00:00 2026-06-17T07:33:42+00:00

I got an algorithm whose objective is to give all possible sums of all

  • 0

I got an algorithm whose objective is to give all possible sums of all combinations in an array of Integer.

private void arraySumPermutation(int value ,int[] arr){
    int N = arr.length;     
    for(int i=0;i<1<<N;i++){
        int sum = 0;                
        for(int j=0;j<N;j++){       

            if((i & 1<<j)>0){
                iCount++;
                sum += arr[j];  
                //S.O.P(sum);
            }
        }

    }
}

I am not able to understand the inner if condition added with bitwise AND.
What is the objective of inner if loop.

if((i & 1<<j)>0)
  • 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-17T07:33:43+00:00Added an answer on June 17, 2026 at 7:33 am

    Let’s represent cominations of N-element set as N-bit numbers, where jth bit is 1 if jth item is included in the combintation, and 0 otherwise. This way you can represent all possible combinations as numbers in range [0, 2N).

    The outer loop iterates over these numbers (1 << N == 2N).

    The inner loop iterates over items of the set and if condition checks whether jth item is included into the current combination. In other words, it checks if jth bit of i is 1.

    1<<j gives you a number where only jth bit is 1, i & (1 << j) resets all bits of i other than that bit, and > checks that result is not 0.

    Note that this code (with ints) only works for N < 31.

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

Sidebar

Related Questions

I am solving this problem of rotating an array and got algorithm and code
I have probem / strange question, i got algorithm with few for loops and
I just implemented QuickSort algorithm from book and got weird output. It works but
I got this formula from a data structure book in the bubble sort algorithm.
I have already made an algorithm for the problem but it still got a
I have applied Two different Image Enhancement Algorithm on a particular Image and got
UPDATE2: I think I got it now: <?php /* * @name Lawler's algorithm PHP
I'm running some tests comparing the sha1 algorithm implemented in javascript - got from
I just got a homework assignment, and it's just creating a linear search algorithm
I'm facing a problem of algorithm. Here's the thing : I've got an image

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.