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

The Archive Base Latest Questions

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

I have a quite difficult problem (perhaps even a NP-hard problem ^^) with looking

  • 0

I have a quite difficult problem (perhaps even a NP-hard problem ^^) with looking for a solution in a massive collection of results. Perhaps there is an algorithm for it.

Below exercise is artificial but is a perfect example to illustrate my issue.

There is a big array with integers. Lets say it has 100.000 elements.

int numbers[] = {-123,32,4,-234564,23,5,....}

I want to check in a relatively quick way if a sum on any 2 numbers from this array is equal to 0. In other words, if the array has “-123” I want to find is there also a “123” number.

The easiest solution would be brute force – check everything with everything. That gives 100.000 x 100.000 a big number 😉 Obviously brute force method can by optimised. Order numbers and check negatives against positive only. My question is – is there something better then optimised brute force to find a solution?

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

    The example you provided can be brute-force solved in O(n^2) time.

    You can start ordering the numbers (O(n·logn)) from smaller to bigger. If you place one pointer at the beginning (the “most negative number”) and other at the end (the “most positive”), you can check if there is such pair of numbers in an additional O(n) steps by following the next procedure:

    • If the numbers at both pointers have the same module, you have the solution
    • If not, move the pointer of the number with bigger module towards “zero” (this is, increase if it is the pointer on the negative side, decrease if it is the positive-side one)
    • Repeat until finding a solution, or the pointers cross.

    Total complexity is O(n·logn)+O(n) = O(n·logn).

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

Sidebar

Related Questions

I have a quite difficult problem with binary files. I have been asked to
I have quite a problem concerning the use of relational database concepts in Delphi
I've encountered with an difficult bug, that Im not quite sure if there is
I am experiencing very difficult (hard to find) problem with my PHP login script.
I have a really difficult problem to solve and Im just wondering what what
we have quite a lot of RPG-programs here, and we do a lot of
I have quite a complex piece of code (JQuery and HTML5 Web SQL) that
I have quite a few buttons in my application, they vary in sizes based
I have quite big document in html format that generated from Microsoft Word. It
I have quite a large VB6 project, with many forms, classes, modules and user

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.