Complexity Theory of Polynomial-Time Problems Lecture 6: 3SUM Part I Karl Bringmann
3SUM given sets π΅,πΆ,π· of π integers are there π β π΅, π β πΆ,π β π· such that π + π + π = 0 ? (we assume that we can add/subtract/compare input integers in constant time) trivial algorithm: π(π / ) well-known: π(π 1 ) Conjecture: no π π 123 algorithm β 3SUM-Hardness [Gajentaan,Overmarsβ95]
More Known Algorithms trivial: π(π / ) well-known: π(π 1 ) using FFT: π(π + π polylogπ) for numbers in {βπ, β¦, π} 789 : ; (789 789 <) : using Word RAM bit-tricks: π(π 1 β ; ) , π(π 1 β ) 789 : < (cell size π₯ = Ξ©(logπ) , [Baran,Demaine,Patrascuβ05] each number fits in a cell) (789 789 <) : no bit-tricks: π(π 1 β ) [Gronlund,Pettieβ14] 789 < we prove a simplified version: Without bit-tricks, 3SUM is in time π(π 1 β =87> 789 789 < Thm: ) 789 <
Equivalent Variants given sets π΅,πΆ,π· of π integers 1) are there π β π΅, π β πΆ,π β π· such that π + π + π = 0 ? replace π· by βπ π β π·} given sets π΅,πΆ,π· of π integers 2) are there π β π΅, π β πΆ,π β π· such that π + π = π ? β π + π β π = 0 given sets π΅,πΆ,π· of π integers and target π’ replace π· by π β π’ π β π·} 3) are there π β π΅, π β πΆ,π β π· such that π + π + π = π’ ? β π + π + (π β π’) = 0 4) given a set π of π integers are there π¦, π§, π¨ β π such that π¦ + π§ + π¨ = 0 ? β : set π΅, πΆ, π· β π β : set π β π + 4π | π β π΅ βͺ πΆ βͺ {π β 4π | π β π·} where π΅,πΆ,π· β {βπ,. . , π}
Outline 1) algorithm for small universe 2) quadratic algorithm 3) small decision tree 4) logfactor improvement 5) some 3SUM-hardness results
Algorithm for Small Numbers π(π + π polylogπ) for numbers in {βπ, β¦, π} add π to each number, then numbers are in {0,. . , 2π} and we want π β π΅, π β πΆ,π β π· such that π + π + π = 3π π¦ ^ define polynomials π \ π¦ β β and similarly π _ π¦ , π ` π¦ ^β\ have degree at most 2π π¦ ^ π¦ b π¦ c compute π π¦ β π \ π¦ β π _ π¦ β π ` π¦ = (β )(β )(β ) ^β\ cβ` bβ_ ( π¦ ^ β π¦ b β π¦ c = π¦ ^fbfc ) what is the coefficient of π¦ /d in π(π¦) ? it is the number of (π, π, π) summing to 3π use efficient polynomial multiplication (via Fast Fourier Transform): polynomials of degree π can be multiplied in time π(π polylogπ)
Outline 1) algorithm for small universe 2) quadratic algorithm 3) small decision tree 4) logfactor improvement 5) some 3SUM-hardness results
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 if π m + π n < βπ : π β π + 1 β¦ return βno solutionβ π <
Quadratic Algorithm given a set π΅ of π integers are there π, π, π β π΅ such that π + π + π = 0 ? sort π΅ in increasing order: π΅ = {π g ,β¦ , π < } for each π β π΅ : check whether there are π, π β π΅ s.t. π + π + π = 0 initialize π = π,π = 1 π g π 1 π / β¦ π < π g while π > 0 and π β€ π : π 1 if π m + π n = βπ : return (π m , π n ,π) π / if π m + π n > βπ : π β π β 1 otherwise: π β π + 1 β¦ return βno solutionβ time π(π) per π β π΅ time π(π 1 ) overall π <
Outline 1) algorithm for small universe 2) quadratic algorithm 3) small decision tree 4) logfactor improvement 5) some 3SUM-hardness results
Decision Tree Complexity 3SUM has a decision tree of depth π(π //1 logπ) Thm:
Recommend
More recommend