|
|
Line 1: |
Line 1: |
| {{unsolved|computer science|Is there an algorithm to solve 3SUM problem faster than <math>O(n^2)</math> time?}}
| | Eusebio is the name women and men use to call my home and I think it's sounds quite good when you say it. I worn to be unemployed yet still now I am a huge cashier. My house is now in South Carolina and I don't plan onto [https://Www.Google.com/search?hl=en&gl=us&tbm=nws&q=changing&btnI=lucky changing] it. It's not a common application but what I like for example doing is bottle blouses collecting and now I do have time to think about on new things. I'm not high-quality at webdesign but retailers . want to check my website: http://circuspartypanama.com<br><br>my web site; [http://circuspartypanama.com clash of clans hack no survey download] |
| In [[computational complexity theory]], the '''3SUM''' problem asks if a given set of <math>n</math> integers, each with absolute value bounded by some polynomial in <math>n</math>, contains three elements that sum to zero. The generalized version, rSUM, asks the same question of r elements. 3SUM can be easily solved in <math>O(n^2)</math> time, and matching <math>\Omega(n^{r/2})</math> lower bounds are known in some specialized [[models of computation]] {{harv|Erickson|1999}}. Slightly faster randomized algorithms are known that exploit [[model of computation|computational-model]] parallelism on a [[Random Access Machine|RAM]] and in the external-memory and [[cache-oblivious]] models {{harv|Baran|Demaine|Pǎtraşcu|2008}}. When the integers are in the range <math>[-u, \dots, u]</math>, 3SUM can be solved in <math>O(n + u\log u)</math> time by representing the input set <math>S</math> as a bit vector, computing the set <math>S+S</math> of all pairwise sums as a [[Convolution#Discrete_convolution|discrete convolution]] using the [[Fast Fourier transform]], and finally comparing this set to <math>-S</math>.
| |
| | |
| ==Quadratic algorithm==
| |
| | |
| Suppose the input array is <math>S[0..n-1]</math>. 3SUM can be solved in <math>O(n^2)</math> time by inserting each number <math>S[i]</math> into a hash table, and then for each index <math>i</math> and <math>j</math>, checking whether the hash table contains the integer <math>-S[i]-S[j]</math>.
| |
| | |
| Alternatively, the algorithm below first sorts the input array and then tests all possible pairs in a careful order that avoids the need to [[binary search]] for the pairs in the sorted list, again achieving <math>O(n^2)</math> time, as follows.<ref>[http://www.ti.inf.ethz.ch/ew/courses/CG09/materials/v12.pdf Visibility Graphs and 3-Sum] by Michael Hoffmann</ref>
| |
| sort(S);
| |
| '''for''' i=0 '''to''' n-3 '''do'''
| |
| a = S[i];
| |
| k = i+1;
| |
| l = n-1;
| |
| '''while''' (k<l) '''do'''
| |
| b = S[k];
| |
| c = S[l];
| |
| '''if''' (a+b+c == 0) '''then'''
| |
| '''output''' a, b, c;
| |
| exit;
| |
| '''else''' '''if''' (a+b+c > 0) '''then'''
| |
| l = l - 1;
| |
| '''else'''
| |
| k = k + 1;
| |
| '''end'''
| |
| '''end'''
| |
| '''end'''
| |
| | |
| The following example shows this algorithm's execution on a small sorted array. Current values of '''a''' are shown in bold, values of '''b''' and '''c''' are shown in red.
| |
| '''-25''' <span style="color:red">-10</span> -7 -3 2 4 8 <span style="color:red">10</span> (a+b+c==-25)
| |
| '''-25''' -10 <span style="color:red">-7</span> -3 2 4 8 <span style="color:red">10</span> (a+b+c==-22)
| |
| . . .
| |
| '''-25''' -10 -7 -3 2 4 <span style="color:red">8</span> <span style="color:red">10</span> (a+b+c==-7)
| |
| -25 '''-10''' <span style="color:red">-7</span> -3 2 4 8 <span style="color:red">10</span> (a+b+c==-7)
| |
| -25 '''-10''' -7 <span style="color:red">-3</span> 2 4 8 <span style="color:red">10</span> (a+b+c==-3)
| |
| -25 '''-10''' -7 -3 <span style="color:red">2</span> 4 8 <span style="color:red">10</span> (a+b+c==2)
| |
| -25 '''-10''' -7 -3 <span style="color:red">2</span> 4 <span style="color:red">8</span> 10 (a+b+c==0)
| |
| | |
| The correctness of the algorithm can be seen as follows. Suppose we have a solution a + b + c = 0. Since the directions of the points only move in one direction, we can run the algorithm until the leftmost pointer points to a. Run the algorithm until either one of the remaining pointers points to a or b, whichever occurs first. Then the algorithm will run until the last pointer points to the remaining term, giving the affirmative solution.
| |
| | |
| ==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 {{harvtxt|Gajentaan|Overmars|1995}} in [[analysis of algorithms]] in [[computational geometry]]. By now there are a multitude of problems that fall into this category.
| |
| | |
| ==Notes==
| |
| {{Reflist}}
| |
| | |
| ==References==
| |
| *{{citation
| |
| | last1 = Baran | first1 = Ilya
| |
| | last2 = Demaine | first2 = Erik D. | author2-link = Erik Demaine
| |
| | last3 = Pătraşcu | first3 = Mihai | author3-link = Mihai Pătraşcu
| |
| | doi = 10.1007/s00453-007-9036-3
| |
| | issue = 4
| |
| | journal = Algorithmica
| |
| | pages = 584–596
| |
| | title = Subquadratic algorithms for 3SUM
| |
| | url = http://erikdemaine.org/papers/3SUM_Algorithmica/
| |
| | volume = 50
| |
| | year = 2008}}.
| |
| *{{citation
| |
| | last1 = Demaine | first1 = Erik D. | author1-link = Erik Demaine
| |
| | last2 = Mitchell | first2 = Joseph S. B. | author2-link = Joseph S. B. Mitchell
| |
| | last3 = O'Rourke | first3 = Joseph | author3-link = Joseph O'Rourke (professor)
| |
| | date = July 2005
| |
| | publisher = [http://maven.smith.edu/~orourke/TOPP/Welcome.html The Open Problems Project]
| |
| | title = Problem 11: 3SUM Hard Problems
| |
| | url = http://cs.smith.edu/~orourke/TOPP/P11.html}}.
| |
| *{{citation
| |
| | last1 = Erickson | first1 = Jeff
| |
| | year = 1999
| |
| | journal = Chicago Journal of Theoretical Computer Science
| |
| | volume = 1999
| |
| | publisher = MIT Press
| |
| | title = Lower bounds for linear satisfiability problems
| |
| | url = http://cjtcs.cs.uchicago.edu/articles/1999/8/contents.html}}.
| |
| *{{citation
| |
| | last1 = Gajentaan | first1 = Anka
| |
| | last2 = Overmars | first2 = Mark H. | author2-link = Mark Overmars
| |
| | doi = 10.1016/0925-7721(95)00022-2
| |
| | issue = 3
| |
| | journal = Computational Geometry: Theory and Applications
| |
| | pages = 165–185
| |
| | title = On a class of O(''n''<sup>2</sup>) problems in computational geometry
| |
| | volume = 5
| |
| | year = 1995}}.
| |
| *{{citation
| |
| | last = King | first = James
| |
| | title = A survey of 3SUM-hard problems
| |
| | url = http://www.cs.mcgill.ca/~jking/papers/3sumhard.pdf
| |
| | year = 2004}}.
| |
| | |
| == See also ==
| |
| * [[Subset sum problem]]
| |
| | |
| [[Category:Computational geometry]]
| |
| [[Category:Polynomial-time problems]]
| |
| [[Category:Unsolved problems in computer science]]
| |
Eusebio is the name women and men use to call my home and I think it's sounds quite good when you say it. I worn to be unemployed yet still now I am a huge cashier. My house is now in South Carolina and I don't plan onto changing it. It's not a common application but what I like for example doing is bottle blouses collecting and now I do have time to think about on new things. I'm not high-quality at webdesign but retailers . want to check my website: http://circuspartypanama.com
my web site; clash of clans hack no survey download