Element distinctness algorithm
A quantum walk algorithm for detecting or finding duplicate values in an arbitrary indexed list.
On this page
Definition, purpose and input assumptions
Element distinctness asks whether any two of N list elements are equal. Unlike the promised collision problem, the input may contain only one duplicate pair. A quantum walk over subsets of indices can exploit partial information while updating a stored subset economically. Ambainis's algorithm achieves the characteristic N^(2/3) query scale in the relevant oracle model.
Mathematical mechanism
A walk state records a subset of indices and associated values. A subset is marked if it contains a duplicate. Neighboring subsets differ by a small number of elements, so updating them requires fewer new oracle calls than rebuilding each subset. The walk's spectral properties and marked fraction determine search cost; it is not simply Grover search over all pairs with an unchanged oracle.
Fully solved reference example
There are N(N-1)/2 unordered pairs. For N=27, this is 351. A naive Grover search over pairs has a square-root scale sqrt(351), about 18.735 pair checks, each querying or accessing two values. The element-distinctness query exponent instead gives N^(2/3)=9 as an asymptotic scale before constants and overhead. These numbers illustrate different scaling laws and are not exact gate counts or a predicted runtime for 27 items.
For list (5,2,9,5), subset {0,3} is marked because both values are 5; subset {0,1} is not. A subset update replacing index 1 by 3 reveals the duplicate with one new value query if the retained value is stored.
Limitations and classical comparison
Classical sorting or hashing solves an explicitly available list in roughly linear or N log N work, depending on model. Quantum comparison must include data access, memory and result extraction. A query bound should not be presented as a speedup over classical hashing with a preloaded table without matched assumptions.
Scientific relationships
Element distinctness uses quantum walks and is distinct from promised collision finding. It depends on oracle access and a carefully accounted memory/update model.
Exact marked fractions for a subset walk
Take a list of ten elements containing one duplicate pair at two specified indices, with every other value distinct. A walk vertex stores a four-element subset of indices and their values. There are C(10,4)=210 such subsets. A marked subset must include both duplicate indices and any two of the other eight, giving C(8,2)=28 marked vertices. The marked fraction is therefore 28/210=2/15, equal to r(r-1)/[N(N-1)] for N=10 and r=4.
This counting differs from searching over all unordered index pairs. A subset contains reusable information about several values, and one update replaces only one member. The stored values of the other three members remain available. In a reversible implementation, removing a stored value can require unquerying it before replacing its index, followed by querying the new value. Thus an update can have a constant number of value-oracle calls even though it also performs nontrivial bookkeeping and duplicate detection.
If there are two disjoint duplicate pairs instead, inclusion-exclusion gives marked fraction 2C(8,2)/C(10,4)-C(6,0)/C(10,4)=55/210=11/42. The subtraction removes the subset containing both pairs, which was counted twice. If three indices share the same value, a subset is marked when it contains at least two of those three. The count is C(3,2)C(7,2)+C(3,3)C(7,1)=70, giving fraction 1/3. Multiplicity structure changes the exact marked fraction even with the same list length and subset size.
The classical walk underlying the construction
Consider the Johnson-graph walk that chooses one of the r stored indices uniformly and replaces it by one of the N-r external indices uniformly. It is regular and has the uniform distribution over subsets as its stationary distribution. For the standard non-lazy transition matrix, the spectral gap from the largest eigenvalue to the next is N/[r(N-r)]. At N=10,r=4 this is 5/12. Making the walk lazy by staying put with probability one half changes the gap to 5/24 and removes possible concerns about negative eigenvalues in a generic mixing interpretation.
The associated quantum-walk construction uses coherent operations related to this transition structure. Its amplitudes do not evolve as an ordinary classical probability distribution. The spectral gap and marked fraction enter the analysis through reflections and phase relations, rather than through a claim that the quantum walk literally samples a classical random trajectory faster.
For a representative search bound, the resource expression has the form S+(1/√ε)(U/√δ+C), where S is setup cost, U update cost, C checking cost, ε a marked-fraction lower bound, and δ a spectral-gap parameter. The precise theorem and walk construction determine constants and allowed error. In the ten-element example, using the lazy gap and the exact marked fraction gives 1/√(εδ)=6. Thus the update contribution in that expression is six times U. It is not an exact statement that six physical walk steps always find the duplicate.
Recovering the two-thirds exponent
When r is well below N, the marked fraction for one duplicate pair scales as r²/N², while the Johnson-walk gap scales as 1/r. Loading a subset costs r value queries, and each update costs a constant number of queries. The resulting leading query scale is r+N/√r. Balancing these two terms gives r on the order of N^{2/3}, with the same order for the total. This derivation explains how reusing partial information improves on rebuilding each candidate subset from scratch.
A direct search over pairs has about N²/2 candidates and hence a query scale proportional to N when a pair check costs a constant number of value accesses. It does not obtain the two-thirds exponent simply by putting all pairs into a superposition. The saving arises from a walk that organizes and reuses a larger stored subset, together with its spectral analysis.
The memory cost grows with r. Besides the index labels, the walk stores enough value information to recognize a collision within the subset. If values have w bits, the raw data scale is r(log₂N+w), before reversible workspace and data-structure overhead. Checking a stored subset can use sorting or another duplicate-detection representation. Counting its value-oracle cost as zero means no additional calls to the input oracle; it does not mean zero gates, zero time, or no classical preprocessing.
Output and classical comparison
A marked subset is an intermediate certificate. The final algorithm must identify two distinct indices within it and verify their equal values. If the question only asks whether all elements are distinct, the output is a decision with a stated error probability; if it asks for a collision, the pair must be extracted. Those output requirements should be separated from the walk's internal state dimension.
For an explicit list in classical memory, hashing gives a natural expected-linear-work baseline under a suitable hash model, while sorting gives a comparison-based alternative. Quantum query statements assume coherent access and do not include arbitrary conversion of a classical input into that access model for free.
Sources
Verification scope
Selected source text checked ·
Queries and memory access require explicit accounting before inferring implementation runtime.