User:Erel Segal/Reduction
Reduction to set intersection
The 3SUMx3 problem can be reduced to the following set intersection problem:
- Given two collections of sets, S and T, find a set from collection S that intersects a set from collection T.
The reduction uses an almost linear hash function.
The hash function maps every element in the three input arrays, X Y and Z, to the range {0,...,R-1}, where R is a certain constant.
Create a collection S based on the elements of X in the following way:
- For every :
Create a collection T based on the elements of Y in the following way:
- For every :
Any element in the intersection of and corresponds to an and a such that:
The expression is always in the range 0,...,R-1, which is the range of h. If there is a such that , then we have:
so we have a candidate for a triple having:
---
The main loop is (given arrays A, B and C):
- For every z in array C:
- If check(z, A,B)
- Return
- If check(z, A,B)
Where the check function checks if there are elements x∈A and y∈B such that: x+y=z.
The check function can be implemented using 2SUM; this takes time O(n), and since it is activated for every element of C, the total run time is O(n^2). But with a solver for an intersection problem, we can do better.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.