Complexity Theory of Polynomial-Time Problems Lecture 7: 3SUM II Sebastian Krinninger
Reminder: 3SUM given sets ๐ต, ๐ถ, ๐ท of ๐ integers are there ๐ โ ๐ต, ๐ โ ๐ถ, ๐ โ ๐ท such that ๐ + ๐ + ๐ = 0 ? well-known: ๐(๐ 2 ) Conjecture: no ๐ ๐ 2โ๐ algorithm โ 3SUM-Hardness Alternative algorithm: ๐( ๐ต โ ๐ถ + |๐ท|) (store negated pairwise sums in hashmap) 2/19 June 16, 2016
Reminder: Hashing Hash function โ: ๐ โ [๐] ๐ฆ โ(๐ฆ) 2 โฏ ๐ 1 Goal: Distribute uniformly, avoid collisions, etc. 3/19 June 16, 2016
Magical hash functions Desired properties for family of hash functions from ๐ โ ๐ (i.e., for every โ chosen from family) Uniform difference: Pr โ ๐ฆ โ โ(๐ง) = ๐ = 1/๐ (for any ๐ฆ, ๐ง โ ๐ s.t. ๐ฆ โ ๐ง and ๐ โ ๐ ) ๐ฆ โ ๐ โถ โ ๐ฆ = ๐ โค 3๐/๐ Balanced: (for any set ๐ = ๐ฆ 1 , โฆ , ๐ฆ ๐ โ ๐ and any ๐ โ ๐ ) โ ๐ฆ + โ ๐ง = โ ๐ฆ + ๐ง (mod ๐) Linear: (for any ๐ฆ, ๐ง โ ๐ ) But: We do not know such a familyโฆ 4/19 June 16, 2016
5/19 June 16, 2016
Almost magical hash functions Desired properties for family of hash functions from ๐ โ ๐ (i.e., for every โ chosen from family) Uniform difference: Pr โ ๐ฆ โ โ(๐ง) = ๐ = 1/๐ (for any ๐ฆ, ๐ง โ ๐ s.t. ๐ฆ โ ๐ง and ๐ โ ๐ ) Almost balanced: Expected number of elements from S hashed to heavy values is ๐(๐) , where value ๐ โ ๐ is heavy if ๐ฆ โ ๐ โถ โ ๐ฆ = ๐ > 3๐/๐ (for any set ๐ = ๐ฆ 1 , โฆ , ๐ฆ ๐ โ ๐ and any ๐ โ ๐ ) โ ๐ฆ + โ ๐ง โ โ ๐ฆ + ๐ง + ๐ โ + 0,1 (mod ๐) Almost linear: (for any ๐ฆ, ๐ง โ ๐ and some integer ๐ โ depending only on โ ) 6/19 June 16, 2016
Definition of hash function Set ๐ = ๐๐ for some ๐ โฅ ๐/2 and ๐, ๐, ๐ powers of 2 โ ๐,๐,๐ = โ ๐,๐ : ๐ โ ๐ โฃ ๐ โ ๐ odd integer and ๐ โ ๐ โ ๐,๐ ๐ฆ = ๐๐ฆ + ๐ mod ๐ div ๐ /๐ Thm: Family โ ๐,๐,๐ is has the uniform difference property, is almost balanced and almost linear with ๐ โ ๐,๐ = (๐ โ 1 mod ๐ ) div ๐ /๐ . (Pairwise independence [Dietzfelbinger โ96] implies uniform difference (easy to check) and almost balanced [Baran et al. โ08]. Almost linear: easy to check.) Rest of this lecture: โ picked randomly from this family 7/19 June 16, 2016
Hashing down the universe Lem: If 3SUM on universe of size ๐(๐ 3 ) solvable in exp. time ๐(๐ 2โ๐ ) , then 3SUM on arbitrary universe solvable in expect. time ๐(๐ 2โ๐ ) . Follows from [Baran et al. โ08] Algorithm: Repeat until output: Pick hash function โ: 1 โฆ ๐ โ 1 โฆ 6๐ 3 at random โข ๐ต โฒ = ๐ โ ๐ต , ๐ถ โฒ = {โ ๐ โฃ ๐ โ ๐ถ} , ๐ท โฒ = โ ๐ โ ๐ + ๐ โ ๐ โ ๐ท โข ๐ตโฒ โฒ = ๐ โ ๐ต , ๐ถโฒ โฒ = {โ ๐ โฃ ๐ โ ๐ถ} , ๐ทโฒ โฒ = โ ๐ โ ๐ + ๐ โ + 1 ๐ โ ๐ท โข Solve two 3SUM instances ๐ต โฒ , ๐ถ โฒ , ๐ท โฒ and ๐ตโฒ โฒ , ๐ถโฒ โฒ , ๐ทโฒ โฒ โข โข If algorithm reports no 3SUM witness: output โno 3SUMโ Consider first reported 3SUM witness ๐ฆ โฒ , ๐ง โฒ , ๐จ โฒ for ๐ต โฒ , ๐ถ โฒ , ๐ท โฒ : โข If โ โ1 ๐ฆโฒ , โ โ1 ๐งโฒ , โ โ1 ๐จ โฒ โ ๐ โ contains witness ๐ฆ, ๐ง, ๐จ : output โข ๐ฆ, ๐ง, ๐จ Consider first reported 3SUM witness ๐ฆโฒ โฒ , ๐ง โฒโฒ , ๐จ โฒโฒ for ๐ต โฒโฒ , ๐ถ โฒโฒ , ๐ท โฒโฒ : โข If โ โ1 ๐ฆโฒโฒ , โ โ1 ๐งโฒโฒ , โ โ1 ๐จ โฒโฒ โ ๐ โ โ 1 contains witness ๐ฆ, ๐ง, ๐จ : โข output ๐ฆ, ๐ง, ๐จ No false negatives: If ๐ฆ + ๐ง = ๐จ , then โ ๐ฆ + โ ๐ง โ โ ๐จ + ๐ โ + 0,1 8/19 June 16, 2016
Running Time We need to bound: โข Number of iterations ๐(1) Number of candidate witnesses ๐(1) โข Then: number of calls to 3SUM algorithm: ๐(1) Number of iterations: Triple ๐ฆ, ๐ง, ๐จ gives false positive if ๐ฆ + ๐ง โ ๐จ and one of โ ๐ฆ + โ ๐ง = โ ๐จ + ๐ โ or โ ๐ฆ + โ ๐ง = โ ๐จ + ๐ โ + 1 Linearity: โ ๐ฆ + โ ๐ง = โ ๐ฆ + ๐ง + ๐ โ or โ ๐ฆ + โ ๐ง = โ ๐ฆ + ๐ง + ๐ โ + 1 Thus, probability that fixed ๐ฆ, ๐ง, ๐จ (with ๐ฆ + ๐ง โ ๐จ ) gives false positive is: 3 1 Pr โ ๐ฆ + ๐ง โ โ ๐จ โ {โ1,0,1} โค 6๐ 3 = (uniform difference) 2๐ 3 Overall probability of false positive : โค ๐ 3 โ 2๐ 3 = 1 1 2 In expectation: 2 iterations until no false positive (waiting time bound) (If no false positive, then algorithm certainly stops) 9/19 June 16, 2016
Running Time We need to bound: โข Number of iterations ๐(1) Number of candidate witnesses ๐(1) โข Then: number of calls to 3SUM algorithm: ๐(1) Number of candidate witnesses: Fix 3SUM witness ๐ฆ โฒ , ๐ง โฒ , ๐จโฒ of instance (๐ต โฒ , ๐ถ โฒ , ๐ท โฒ ) Let ๐ฆ โ โ โ โ1 ๐ฆโฒ 1 For every ๐ฆ โ ๐ฆ โ : Pr โ ๐ฆ = โ ๐ฆ โ = (uniform difference) 6๐ 3 ๐น โ โ1 ๐ฆ โฒ ๐ โค 1 + 4๐ 3 โค 2 Similarly: ๐น โ โ1 ๐ง โฒ โค 2 , ๐น โ โ1 ๐จ โฒ โค 2 ๐น โ โ1 ๐ฆ โฒ โช โ โ1 ๐ง โฒ โช โ โ1 ๐จ โฒ โค ๐(1) (linearity of expectation) In expectation, algorithm manually checks constant number of candidate witnesses per iteration 10/19 June 16, 2016
Convolution 3SUM Given array ๐ต 1 โฆ ๐ of integers are there ๐, ๐ such that ๐ต ๐ + ๐ต ๐ = ๐ต[๐ + ๐] ? ๐ฆ + ๐ง ๐ฆ ๐ง ๐ ๐ ๐ + ๐ trivial algorithm: ๐(๐ 2 ) Thm: There is no ๐(๐ 2โ๐ ) algorithm for Convolution 3SUM unless the 3SUM Conjecture fails. [ Pฤtraศcu 2010] Stepping stone towards hardness of other โstructuredโ problems 11/19 June 16, 2016
Reduction from 3SUM Given set ๐ โ [๐] of integers are there ๐ฆ, ๐ง, ๐จ โ ๐ such that ๐ฆ + ๐ง = ๐จ ? Preprocessing: Check if there is a solution 2๐ฆ = ๐จ ๐ ๐ log ๐ Pick random hash function โ: ๐ โ ๐ (almost linear, etc.) For this proof: assume โ is almost balanced and linear (magicallyโฆ) 3๐/๐ โฎ 1 2 โฏ 1 ๐ In expectation: ๐ ๐ elements in buckets with load > 3๐/๐ (almost bal.) For each such ๐ฆ : check for 3SUM triple involving ๐ฆ ๐ ๐๐ (in exp.) 12/19 June 16, 2016
Convolution 3SUM instance 3๐ Number elements in each bucket from 0 to ๐ โ 1 Iterate over all triples ๐, ๐, ๐ โ 3๐/๐ ๐ ๐ ๐ ๐ข โฏ ๐ 1 โฏ โฏ โฏ For every bucket ๐ข : Put ๐ -th element to ๐ต[8๐ข + 1] โข Put ๐ -th element to ๐ต[8๐ข + 3] โข โข Put ๐ -th element to ๐ต[8๐ข + 4] Set all other array entries to โ (sufficiently large number) 3 3๐ instances of Convolution 3SUM ๐ 13/19 June 16, 2016
Correctness Assume ๐ฆ + ๐ง = ๐จ Then โ ๐ฆ + โ ๐ง = โ ๐จ (mod ๐) (linearity) If ๐ฆ = ๐ง , triple found in preprocessing If ๐ฆ , ๐ง , or ๐จ hashed to heavy bucket: triple found in second step Either โ ๐ฆ + โ ๐ง = โ ๐จ or โ ๐ฆ + โ ๐ง = โ ๐จ + ๐ Duplicate array for Convolution 3SUM instance ๐ต 8โ ๐ฆ + 1 + ๐ต 8โ ๐ง + 3 = ๐ต 8โ ๐จ + 4 or ๐ต 8โ ๐ฆ + 1 + ๐ต 8โ ๐ง + 3 = ๐ต 8(โ ๐จ + ๐) + 4 Thus, no false negatives. Also no false positives: ๐ต ๐ + ๐ต ๐ = ๐ต ๐ + ๐ only if ๐ = 8๐ข 1 + 1 and ๐ = 8๐ข 2 + 3 Observation: ( ๐ฆ + ๐ง = ๐จ mod 8 has unique solution over 1,3,4 and ๐ต ๐ โ ๐ต[๐] )
Running Time Assumption: Convolution 3SUM in time ๐(๐ 2โ๐ ) 3 ๐ ๐ 2โ๐ Total expected running time: ๐ ๐ log ๐ + ๐๐ + ๐ Set ๐ = ๐ 1โ๐/4 Total time: ๐ ๐ 2โ๐/4 Contradicts 3SUM Conjecture
Set Disjointness Problem 1. Preprocess subsets ๐, โฌ โ ๐ over universe ๐ 2. Answer queries : Given ๐ต โ ๐, ๐ถ โ โฌ , is ๐ต โฉ ๐ถ โ โ ? Repeated queries (Static) data structure Queries not known in advance Goal: Lower bound on preprocessing and query time Offline Set Disjointness: ๐ queries known in advance (part of input)
Reduction to 3SUM [Kopelowitz et al] Thm: Let ๐ ๐ be such that 3SUM requires expected time ฮฉ ๐ 2 /๐(๐) . For any constant 0 โค ๐ฟ < 1 , let ALG be an algorithm for offline Set Disjointness where ๐ = โฌ = ฮ(๐ log ๐) , ๐ = ฮ ๐ 2โ2๐ฟ , each set in ๐ โช โฌ has at most ๐(๐ 1โ๐ฟ ) elements from ๐ , and ๐ = ฮ ๐ 1+๐ฟ log ๐ . Then ALG requires expected time ฮฉ ๐ 2 /๐(๐) . Assuming the 3SUM conjecture, for any 0 < ๐ฟ < 1 , any data Cor: structure for Set Disjointness has 1+๐ฟ 2 2โ๐ฟโ๐(1) ๐ข ๐ + ๐ 2โ๐ฟ ๐ข ๐ = ฮฉ ๐ where ๐ is the sum of the set sizes, ๐ข ๐ is the preprocessing time, and ๐ข ๐ is the time per query. (From Thm: ๐ = ฮ ๐ 2โ๐ฟ log ๐ ) Example: Data structures with constant query time Make ๐ฟ tend to 1 , need ๐ข ๐ = ฮฉ ๐ 2โ๐(1) Evidence that trivial preprocessing algorithm is optimal (for constant query)
Recommend
More recommend