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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:41:22+00:00 2026-06-08T15:41:22+00:00

Given a list of N non-negative integers, propose an algorithm to check if the

  • 0

Given a list of N non-negative integers, propose an algorithm to check if the sum of X numbers from the list equals the remaining N-X.

In other words, a simpler case of the Subset sum problem which involves the entire set.

An attempted solution

Sort the elements of the list in descending order. Initialize a variable SUM to the first element. Remove first element (largest, a(1)). Let a(n) denote the n-th element in current list.

While list has more than one element,

  1. Make SUM equal to SUM + a(1) or SUM - a(1), whichever is closest to a(2). (where closest means |a(2) - SUM_POSSIBLE| is minimum).

  2. Remove a(1).

If the SUM equals -a(1) or a(1), there exists a linear sum.

The problem

I cannot seem to resolve above algorithm, if it is correct, I would like a proof.
If it is wrong (more likely), is there a way to get this done in linear time?

PS: If I’m doing something wrong please forgive :S

  • 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-08T15:41:24+00:00Added an answer on June 8, 2026 at 3:41 pm

    Notice that you want the sum of x numbers to be equal to the sum of the other N-x numbers.
    You can simplify this by saying you want to see if there’s a subset which sums up to S/2 where S is the total sum of the whole set.

    So, you can calculate the Sum you need to get to with one iteration (O(n)).

    Then just use a known algorithm like Knapsack to find a subset that meets your sum.

    Another more “mathematical” explanation: Dynamic Programming – 3 : Subset Sum

    Edit:

    As an answer to your other question, your algorithm is wrong. consider this list of numbers:

    {3,3,4,4}

    The total sum is 14, so you’re looking for a subset with the sum of 7. Obviously it will be 3+4.

    Your algorithm will return false after examining the 2 3’s

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

Sidebar

Related Questions

I'm trying to wrap words and words sequence from a given list with preg_replace.
Given a list of numbers, how does one find differences between every ( i
Given a list of numbers: L = [1, 2, 3, 4, 5] How do
Given a non-negative integer n and an arbitrary set of inequalities that are user-defined
Does there exist an algorithm which, given an ordered list of symbols {a1, a2,
Given a list of integers, how can I best find an integer that is
How can I return a list of fields from a given table that contain
I have a matrix, i.e., a non-ragged list of lists, and given a list
Given an R list, I wish to find the index of a given list
The original code was somehow complex, i simplify it as: Given: list of class

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.