kb/data/en.wikipedia.org/wiki/3SUM-2.md

7.1 KiB
Raw Blame History

title chunk source category tags date_saved instance
3SUM 3/3 https://en.wikipedia.org/wiki/3SUM reference science, encyclopedia 2026-05-05T11:01:54.553179+00:00 kb-cron

If there is a solution for 3SUM:

    z
    =
    x
    +
    y
  

{\displaystyle z=x+y}

, then:

    T
    [
    h
    (
    z
    )
    ]
    =
    T
    [
    h
    (
    x
    )
    ]
    +
    T
    [
    h
    (
    y
    )
    ]
  

{\displaystyle T[h(z)]=T[h(x)]+T[h(y)]}

and

    h
    (
    z
    )
    =
    h
    (
    x
    )
    +
    h
    (
    y
    )
  

{\displaystyle h(z)=h(x)+h(y)}

, so this solution will be found by the Conv3SUM solver on T. Conversely, if a Conv3SUM is found on T, then obviously it corresponds to a 3SUM solution on S since T is just a permutation of S. This idealized solution doesn't work, because any hash function might map several distinct elements of S to the same cell of T. The trick is to create an array

      T
      
        
      
    
  

{\displaystyle T^{*}}

by selecting a single random element from each cell of T, and run Conv3SUM on

      T
      
        
      
    
  

{\displaystyle T^{*}}

. If a solution is found, then it is a correct solution for 3SUM on S. If no solution is found, then create a different random

      T
      
        
      
    
  

{\displaystyle T^{*}}

and try again. Suppose there are at most R elements in each cell of T. Then the probability of finding a solution (if a solution exists) is the probability that the random selection will select the correct element from each cell, which is

    (
    1
    
      /
    
    R
    
      )
      
        3
      
    
  

{\displaystyle (1/R)^{3}}

. By running Conv3SUM

      R
      
        3
      
    
  

{\displaystyle R^{3}}

times, the solution will be found with a high probability. Unfortunately, we do not have linear perfect hashing, so we have to use an almost linear hash function, i.e. a function h such that:

    h
    (
    x
    +
    y
    )
    =
    h
    (
    x
    )
    +
    h
    (
    y
    )
  

{\displaystyle h(x+y)=h(x)+h(y)}

or

    h
    (
    x
    +
    y
    )
    =
    h
    (
    x
    )
    +
    h
    (
    y
    )
    +
    1
  

{\displaystyle h(x+y)=h(x)+h(y)+1}

This requires to duplicate the elements of S when copying them into T, i.e., put every element

    x
    ∈
    S
  

{\displaystyle x\in S}

both in

    T
    [
    h
    (
    x
    )
    ]
  

{\displaystyle T[h(x)]}

(as before) and in

    T
    [
    h
    (
    x
    )
    ]
    
    1
  

{\displaystyle T[h(x)]-1}

. So each cell will have 2R elements, and we will have to run Conv3SUM

    (
    2
    R
    
      )
      
        3
      
    
  

{\displaystyle (2R)^{3}}

times.

== 3SUM-hardness == A problem is called 3SUM-hard if solving it in subquadratic time implies a subquadratic-time algorithm for 3SUM. The concept of 3SUM-hardness was introduced by Gajentaan & Overmars (1995). They proved that a large class of problems in computational geometry are 3SUM-hard, including the following ones. (The authors acknowledge that many of these problems are contributed by other researchers.)

Given a set of lines in the plane, are there three that meet in a point? Given a set of non-intersecting axis-parallel line segments, is there a line that separates them into two non-empty subsets? Given a set of infinite strips in the plane, do they fully cover a given rectangle? Given a set of triangles in the plane, compute their measure. Given a set of triangles in the plane, does their union have a hole? A number of visibility and motion planning problems, e.g., Given a set of horizontal triangles in space, can a particular triangle be seen from a particular point? Given a set of non-intersecting axis-parallel line segment obstacles in the plane, can a given rod be moved by translations and rotations between a start and finish positions without colliding with the obstacles? By now there are a multitude of other problems that fall into this category. An example is the decision version of X + Y sorting: given sets of numbers X and Y of n elements each, are there n² distinct x + y for x ∈ X, y ∈ Y?

== See also == Subset sum problem

== Notes ==

== References == Kane, Daniel M.; Lovett, Shachar; Moran, Shay (2018), "Near-optimal linear decision trees for k-SUM and related problems", Proceedings of the 50th Annual ACM SIGACT Symposium on Theory of Computing, pp. 554563, arXiv:1705.01720, doi:10.1145/3188745.3188770, ISBN 9781450355599, S2CID 30368541 Chan, Timothy M. (2020), "More logarithmic-factor speedups for 3SUM, (median,+)-convolution, and some geometric 3SUM-hard problems", ACM Transactions on Algorithms, 16 (1) 7: 123, doi:10.1145/3363541, MR 4060405 Grønlund, Allan; Pettie, Seth (2018), "Threesomes, degenerates, and love triangles", Journal of the ACM, 65 (4) 22: 125, arXiv:1404.0799, doi:10.1145/3185378, MR 3795516 Freund, Ari (2017), "Improved Subquadratic 3SUM", Algorithmica, 44 (2): 440458, doi:10.1007/s00453-015-0079-6, S2CID 253979651. Gold, Omer; Sharir, Micha (2017), "Improved Bounds for 3SUM, k-SUM, and linear degeneracy", in Pruhs, Kirk; Sohler, Christian (eds.), 25th Annual European Symposium on Algorithms, ESA 2017, September 46, 2017, Vienna, Austria, LIPIcs, vol. 87, Schloss Dagstuhl Leibniz-Zentrum für Informatik, pp. 42:142:13, doi:10.4230/LIPICS.ESA.2017.42, ISBN 978-3-95977-049-1, S2CID 691387 Baran, Ilya; Demaine, Erik D.; Pătraşcu, Mihai (2008), "Subquadratic algorithms for 3SUM", Algorithmica, 50 (4): 584596, doi:10.1007/s00453-007-9036-3, S2CID 9855995. Demaine, Erik D.; Mitchell, Joseph S. B.; O'Rourke, Joseph (July 2005), "Problem 11: 3SUM Hard Problems", The Open Problems Project, retrieved 2008-09-02{{citation}}: CS1 maint: deprecated archival service (link). Erickson, Jeff (1999), "Lower bounds for linear satisfiability problems", Chicago Journal of Theoretical Computer Science, 1999, MIT Press. Gajentaan, Anka; Overmars, Mark H. (1995), "On a class of O(n2) problems in computational geometry", Computational Geometry: Theory and Applications, 5 (3): 165185, doi:10.1016/0925-7721(95)00022-2, hdl:1874/17058. King, James (2004), A survey of 3SUM-hard problems (PDF).