Skip to main content

\(\mathrm {3SUM}\), \(\mathrm {3XOR}\), Triangles


Pǎtraşcu (STOC ’10) reduces the \(\mathrm {3SUM}\) problem to listing triangles in a graph. In the other direction, we show that if one can solve \(\mathrm {3SUM}\) on a set of size \(n\) in time \(n^{1+\epsilon }\) then one can list \(t\) triangles in a graph with \(m\) edges in time \(\tilde{O}(m^{1+\epsilon }t^{1/3-\epsilon /3})\). Our result builds on and extends works by the Paghs (PODS ’06) and by Vassilevska and Williams (FOCS ’10). We make our reductions deterministic using tools from pseudorandomness. We then re-execute both Pǎtraşcu’s reduction and ours for the variant \(\mathrm {3XOR}\) of \(\mathrm {3SUM}\) where integer summation is replaced by bit-wise xor. As a corollary we obtain that if \(\mathrm {3XOR}\) is solvable in linear time but \(\mathrm {3SUM}\) requires quadratic randomized time, or vice versa, then the randomized time complexity of listing \(m\) triangles in a graph with \(m\) edges is \(m^{4/3}\) up to a factor \(m^\alpha \) for any \(\alpha > 0\).

This is a preview of subscription content, access via your institution.


  1. In [5, 20] they appear to use this lemma with a hash function that is not known to satisfy the hypothesis of the lemma. However probably one can use instead similar hash functions such as one in [9] that does satisfy the hypothesis. We thank Martin Dietzfelbinger for a discussion on hash functions.


  1. Ailon, N., Chazelle, B.: Lower bounds for linear degeneracy testing. J. ACM 52(2), 157–171 (2005)

    MATH  MathSciNet  Article  Google Scholar 

  2. Alon, N., Goldreich, O., Håstad, J., Peralta, R.: Simple constructions of almost \(k\)-wise independent random variables. Random Struct. Algorithms 3(3), 289–304 (1992)

    MATH  Article  Google Scholar 

  3. Amossen, R.R.: Scalable Query Evaluation in Realational Databases. PhD Thesis, IT University of Copenhagen (2011)

  4. Alon, N., Yuster, R., Zwick, U.: Finding and counting given length cycles. Algorithmica 17(3), 209–223 (1997)

    MATH  MathSciNet  Article  Google Scholar 

  5. Baran, I., Demaine, E.D., Pǎtraşcu, M.: Subquadratic algorithms for 3sum. Algorithmica 50(4), 584–596 (2008)

    MATH  MathSciNet  Article  Google Scholar 

  6. Bhattacharyya, A., Indyk, P., Woodruff, D.P., Xie, N.: The complexity of linear dependence problems in vector spaces. In: ACM Innovations in Theoretical Computer Science Conference (ITCS), pp. 496–508 (2011)

  7. Bjőrklund, A., Pagh, R., Williams, V.V., Zwick, U.: Listing triangles. In: Colloquium on Automata, Languages and Programming (ICALP) (2014)

  8. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge, MA (2001)

  9. Dietzfelbinger, M.: Universal hashing and \(k\)-wise independent random variables via integer arithmetic without primes. In: Symposium on Theoretical Aspects of Computer Science (STACS), pp. 569–580 (1996)

  10. Elkin, M.: An improved construction of progression-free sets (2008). arXiv:0801.4310

  11. Erickson, J.: Lower bounds for linear satisfiability problems. Chic. J. Theor. Comput. Sci. (1999)

  12. Gajentaan, A., Overmars, M.H.: On a class of \({O}(n^2)\) problems in computational geometry. Comput. Geom. 5, 165–185 (1995)

    MATH  MathSciNet  Article  Google Scholar 

  13. Gutfreund, D., Viola, E.: Fooling parity tests with parity gates. In: 8thWorkshop on Randomization and Computation (RANDOM), pp. 381–392. Springer (2004)

  14. Impagliazzo, R., Paturi, R., Zane, F.: Which problems have strongly exponential complexity? J. Comput. Syst. Sci. 63(4), 512–530 (2001)

    MATH  MathSciNet  Article  Google Scholar 

  15. Jorgesen, A.G., Pettie, S.: Threesomes, degenerates, and love triangles. In: IEEE Symposium on Foundations of Computer Science (FOCS) (2014)

  16. Maslen, D.K., Rockmore, D.N.: Generalized FFTs—a survey of some recent results. In: Groups and Computation, II (New Brunswick, NJ, 1995), volume 28 of DIMACS Ser. Discrete Math. Theor. Comput. Sci., pp. 183–237. Amer. Math. Soc., Providence, RI (1997)

  17. Naor, J., Naor, M.: Small-bias probability spaces: efficient constructions and applications. SIAM J. Comput. 22(4), 838–856 (1993)

    MATH  MathSciNet  Article  Google Scholar 

  18. Nisan, N., Wigderson, A.: Hardness vs randomness. J. Comput. Syst. Sci. 49(2), 149–167 (1994)

    MATH  MathSciNet  Article  Google Scholar 

  19. O’Bryant, K.: Sets of integers that do not contain long arithmetic progressions (2008). arXiv:0811.3057

  20. Pǎtraşcu, M.: Towards polynomial lower bounds for dynamic problems. In: ACM Symposium on the Theory of Computing (STOC), pp. 603–610 (2010)

  21. Pagh, A., Pagh, R.: Scalable computation of acyclic joins. In: ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (PODS), pp. 225–232 (2006)

  22. Pǎtraşcu, M., Williams, R.: On the possibility of faster SAT algorithms. In: ACM-SIAM Symposium on Discrete Algorithms (SODA), pp. 1065–1075 (2010)

  23. Ruzsa, I.Z.: Solving a linear equation in a set of integers I. Acta Arith. LXV(3), 261–263 (1993)

  24. Vardy, A.: The intractability of computing the minimum distance of a code. IEEE Trans. Inf. Theory 43(6), 1757–1766 (1997)

    MATH  MathSciNet  Article  Google Scholar 

  25. Viola, E.: Reducing 3XOR to listing triangles, an exposition (2011).

  26. Vassilevska, V., Williams, R.: Finding, minimizing, and counting weighted subgraphs. In: ACM Symposium on the Theory of Computing (STOC), pp. 455–464 (2009)

  27. Williams, V.V., Williams, R.: Subcubic equivalences between path, matrix and triangle problems. In: IEEE Symposium on Foundations of Computer Science (FOCS), pp. 645–654 (2010)

Download references


We are very grateful to Rasmus Pagh and Virginia Vassilevska Williams for answering many questions on finding triangles in graphs. Rasmus also pointed us to [3, 21]. We also thank Siyao Guo for pointing out that a step in a previous proof of Lemma 14 was useless, and Ryan Williams for stimulating discussions. Finally, we thank the anonymous referees for their helpful comments.

Author information

Authors and Affiliations


Corresponding author

Correspondence to Zahra Jafargholi.

Additional information

Supported by NSF Grants CCF-0845003, CCF-1319206.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Jafargholi, Z., Viola, E. \(\mathrm {3SUM}\), \(\mathrm {3XOR}\), Triangles. Algorithmica 74, 326–343 (2016).

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI:


  • \(\mathrm {3SUM}\)
  • \(\mathrm {3XOR}\)
  • Triangles
  • Algorithms
  • Derandomization