6SUM: for a set S of n integers, is there a subset S with exactly 6 elements that sum with 0? How to do better than O (n ^ 3)?

I thought of this simple algorithm to solve the 6SUM problem using O and n space (n ^ 3): Create all sets of triples and put them in a hash table where the key is the sum of triples. Then we sort through the keys of the hash table: for each key k1 see, Is there another key k2, so k2 = S-k1

What is a more efficient algorithm? This is not a homework problem.

+3
source share
1 answer

Omega (n ^ 6), O (n ^ 3) . -. O (n ^ 3 logn), .

, P, 6 , .. .

3-SUM, , r-sum , o (n ^ [r/2]) (: smallOH [x] = >= x, [ 5/2] = 3) .

3-SUM , , .

, , O (n ^ 3) (.. o (n ^ 3)) .

+4

All Articles