Finding sequence that maps to a given sum

  • Thread starter Thread starter hholzer
  • Start date Start date
  • Tags Tags
    Sequence Sum
Click For Summary
SUMMARY

The discussion focuses on finding indices i and j in an array A such that the sum of the elements from A[i] to A[j] equals a given number s. Participants explore various methods, including the use of a hashtable and aggregate arrays, to achieve this task. While a linear time solution is sought, the consensus indicates that achieving this efficiently remains challenging, with suggestions leaning towards O(n^2) complexity if a table is precomputed. The conversation highlights the complexity of the problem and the limitations of current approaches.

PREREQUISITES
  • Understanding of array manipulation and indexing
  • Familiarity with hashtables and their applications
  • Knowledge of time complexity analysis
  • Basic concepts of aggregate functions in programming
NEXT STEPS
  • Research efficient algorithms for subarray sum problems
  • Learn about the use of hashtables in optimizing search operations
  • Explore aggregate array techniques for performance enhancement
  • Investigate advanced data structures that may reduce time complexity
USEFUL FOR

Software developers, algorithm enthusiasts, and anyone interested in optimizing array sum calculations in programming.

hholzer
Messages
36
Reaction score
0
given array A and number s, find i,j so sum of A[i..j] = s

Can this be done in linear time? I've thought of using a hashtable
but I would be interested in other methods.
 
Technology news on Phys.org
Hmm -- you could create an aggregate array to start (n time). But I don't think you can get away from trying all of the options, sumsInArray>s, and doing a search for the difference you want (the series you are searching is monotonic so that should help). That doesn't get you to linear yet though. n + n(s>S)*log(n(s<S))

If you don't mind making a table at the get go and eating n^2, then that would work.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
8
Views
2K
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
Replies
5
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K