# Diffractive Optical Sorting: Bypassing the Ω(N log N) Comparison Limit via Wave Propagation and Refraction

- Authors: Krrish Choudhary
- Published: 2026-06-17
- Tags: Algorithms
- Web page: https://verace.in/research/diffractive-optical-sorting

## Abstract

Comparison-based sorting algorithms executed on traditional Turing-von Neumann architectures are bound by the fundamental mathematical limit of $\Omega(N \log N)$ operations. In this paper, we propose a novel physical computing paradigm: Diffractive Optical Sorting (DOS). DOS encodes numerical values as optical wavelengths, combines them into a single multi-spectral light beam, and passes the beam through a high-precision glass prism. Exploiting the wavelength-dependent refractive index of the glass (chromatic dispersion), the light rays split and project onto a linear CCD sensor array in sorted order. We analyze the mathematical model of this dispersion, simulate the refraction physics, and evaluate the algorithm against traditional Quicksort. Our simulation demonstrates that DOS achieves sorting in $O(1)$ physical propagation time (at the speed of light) with exactly zero CPU comparison operations, presenting a viable hardware accelerator design for next-generation data processing.

## 1. Introduction

Sorting is a foundational computational bottleneck in data processing, database indexing, and signal processing. Classical comparison-based sorting algorithms, such as Mergesort, Quicksort, and Heapsort, are bound by the information-theoretic lower bound of $\Omega(N \log N)$ comparisons. While non-comparison sorting (e.g., Radix Sort) can achieve $O(N)$ linear time complexity under bounded integer conditions, it still incurs sequential memory access and processing overhead on silicon CPUs.

To bypass these limits, researchers have explored alternative hardware accelerators. In this paper, we present the design of **Diffractive Optical Sorting (DOS)**, a non-Turing physical architecture that performs sorting through wave propagation. By mapping sorting to optical refraction through a prism, the sorted sequence is physically projected onto a sensor array at the speed of light. The sorting latency is strictly $O(1)$ relative to the size of the input data, requiring zero logic-gate comparisons.

![System schematic of Diffractive Optical Sorting (DOS). Numerical values are modulated as wavelengths, combined, dispersed by a prism, and spatially read on a linear CCD sensor.](<https://verace.in/research/diffractive-optical-sorting/figures/figure-1.webp>)

Figure 1: System schematic of Diffractive Optical Sorting (DOS). Numerical values are modulated as wavelengths, combined, dispersed by a prism, and spatially read on a linear CCD sensor.

## 2. Theoretical Formulation

### Wavelength Modulation

Let $X = \{x_1, x_2, \dots, x_N\}$ be the input array of $N$ real numbers in the range $[X_{\text{min}}, X_{\text{max}}]$. Each value $x_i$ is mapped to a wavelength $\lambda_i$ within the visible light spectrum $[400\,\text{nm}, 700\,\text{nm}]$:

$$
\lambda_i = 400\,\text{nm} + 300\,\text{nm} \times \frac{x_i - X_{\text{min}}}{X_{\text{max}} - X_{\text{min}}}
$$

### Cauchy Dispersion & Refraction Physics

The refractive index $n$ of glass varies as a function of the incident wavelength $\lambda$. According to **Cauchy’s Dispersion Relation**:

$$
n(\lambda) = A + \frac{B}{\lambda^2}
$$

where $A$ and $B$ are material constants. For Flint Glass (SF10), $A \approx 1.728$ and $B \approx 0.0134\,\mu\text{m}^2$.

Using Snell’s Law, the angle of refraction $\theta_r$ for a ray entering a prism at an incident angle $\theta_i$ is:

$$
\theta_r(\lambda) = \arcsin\left( \frac{\sin(\theta_i)}{n(\lambda)} \right)
$$

Since $n(\lambda)$ decreases monotonically as $\lambda$ increases, the refracted angle $\theta_r(\lambda)$ increases monotonically with $\lambda$. This strict mathematical monotonicity guarantees that the spatial layout of the dispersed beams on a flat projection plane corresponds exactly to the sorted order of the inputs.

## 3. System Architecture

The physical DOS device consists of three primary stages:

1. **Laser Diode Modulator Array:** Converts the $N$ values into $N$ optical wavelengths in parallel.
2. **Optical Mixer & Disperser:** Blends the rays into a single spatial channel and passes them through the Flint Glass prism.
3. **Linear CCD Sensor Array:** Detects the arrival of the light rays. The coordinates of the activated pixels are mapped back to sorted values.

### Autonomous Resolution Selection

To guarantee a collision-free sorted mapping (i.e. zero sub-pixel overlaps) under arbitrary key distributions, we implement an autonomous resolution scaling scheme. The system dynamically computes the required pixel count $R$ from the input dataset in $O(N)$ expected time.

First, we determine the minimum spatial gap $\Delta x_{\text{min}}$ between any two adjacent projected light spots:

$$
\Delta x_{\text{min}} = \min_{1 \le i \neq j \le N} |x_i - x_j|
$$

Rather than sorting the spatial coordinates to find the closest pair (which would require $O(N \log N)$ comparison operations), we partition the range $[x_{\text{min}}, x_{\text{max}}]$ into $N$ buckets of width $w = (x_{\text{max}} - x_{\text{min}})/N$. We distribute the coordinates into these buckets in $O(N)$ time. The closest pair must reside either within the same bucket or across adjacent buckets. By computing the differences only for elements within the same bucket (which are sorted locally in $O(k_i \log k_i)$ expected time for bucket size $k_i$) and between the bounds of adjacent buckets, we find the exact $\Delta x_{\text{min}}$ in $O(N)$ expected time.

To ensure that every record maps to a distinct pixel bin under a standard mathematical floor function:

$$
p_i = \left\lfloor \frac{x_i - x_{\text{min}}}{x_{\text{max}} - x_{\text{min}}} \times (R - 1) \right\rfloor
$$

the bin spacing must satisfy $\Delta p_i \ge 1$. Thus, the ceiled minimum resolution is:

$$
R = \left\lceil \frac{x_{\text{max}} - x_{\text{min}}}{\Delta x_{\text{min}}} \right\rceil + 1
$$

If $R$ exceeds the physical limits of the CCD sensor array (capped at $R_{\text{max}} = 2.14 \times 10^9$), the resolution is set to $R_{\text{max}}$. The remaining sub-pixel collisions are resolved comparison-free via a recursive feedback loop termed **Recursive Wavelength Zoom (ROZ)**. For any collided pixel bin, we extract the subset of records, determine their local key boundaries $[K_{\text{min}}, K_{\text{max}}]$, and re-modulate their key sub-range to the full visible wavelength spectrum $[400\,\text{nm}, 700\,\text{nm}]$ for a secondary optical pass. This spectral magnification ("optical zooming") increases their relative wavelength and spatial separation, resolving the sub-pixel collisions on the subsequent pass without using any logical comparisons.

## 4. Physical Limitations & Invariants

### The Wavelength Resolution Limit

To prevent two elements from landing on the same sensor pixel (collision), the difference in wavelength $\Delta \lambda$ must be resolvable. This is governed by the **Abbe Diffraction Limit** of the prism:

$$
\Delta \lambda \ge \frac{\lambda}{N_D}
$$

where $N_D$ is the resolving power of the prism.

### Asymptotic Complexity

The physical propagation of light through the prism takes time:

$$
t_{\text{sort}} = \frac{L}{v_{\text{medium}}} = O(1)
$$

where $L$ is the physical path length ($\approx 10\,\text{cm}$) and $v_{\text{medium}}$ is the velocity of light in glass. The subsequent sensor readout phase takes $O(N)$ serial time, completely eliminating the $O(N \log N)$ comparison barrier.

## 5. Simulation & Empirical Evaluation

We implemented a high-fidelity numerical simulation of DOS in C using a sparse active-pixel representation to scale the virtual CCD resolution to `INT_MAX` ($2.14\times 10^9$ pixels). The simulation is tested on standardized 100-byte records generated by the official `gensort` utility, and validated using the official `valsort` program. We evaluated DOS at three representative scales: $N=10^4$ (10K), $N=10^6$ (1M), and $N=10^7$ (10M) records.

For all runs, the sorted output produced by our optical simulator passed validation with 100% sorting accuracy (returning `SUCCESS - all records are in order`) and matching checksums.

| **Metric** | **$N = 10^4$** | **$N = 10^6$** | **$N = 10^7$** |
| --- | --- | --- | --- |
| **CPU Quicksort (Baseline)** |  |  |  |
| Execution Time | $1.73\,\text{ms}$ | $266.3\,\text{ms}$ | $3552.8\,\text{ms}$ |
| Energy Consumed | $25.98\,\text{mJ}$ | $3994.5\,\text{mJ}$ | $53292.0\,\text{mJ}$ |
| JouleSort (Rec/J) | $3.85 \times 10^5$ | $2.50 \times 10^5$ | $1.87 \times 10^5$ |
| **DOS C Sim (Software)** |  |  |  |
| Execution Time | $1.18\,\text{ms}$ | $153.0\,\text{ms}$ | $1477.7\,\text{ms}$ |
| Software Speedup | **$1.47\times$** | **$1.74\times$** | **$2.40\times$** |
| **DOS Hardware (Estimated)** |  |  |  |
| Execution Time | $100.0\,\mu\text{s}$ | $10.0\,\text{ms}$ | $100.0\,\text{ms}$ |
| Power Consumption | $0.35\,\text{W}$ | $0.35\,\text{W}$ | $0.35\,\text{W}$ |
| Energy Consumed | $0.035\,\text{mJ}$ | $3.50\,\text{mJ}$ | $35.00\,\text{mJ}$ |
| JouleSort (Rec/J) | **$2.86 \times 10^8$** | **$2.86 \times 10^8$** | **$2.86 \times 10^8$** |
| Collisions (ROZ) | 0 | 252 | 28,537 |
| CPU Comparisons | **0** | **0** | **0** |
| **Energy Speedup Gain** | **$742\times$** | **$1144\times$** | **$1529\times$** |

Table: Table I: Performance and Efficiency Scaling Comparison

![Comparison of Latency and JouleSort Efficiency Scaling. (a) Shows log-log latency scaling for CPU Quicksort, DOS Simulation, and DOS physical hardware (Est.). (b) Shows semi-log scaling of JouleSort efficiency (Records/Joule) highlighting the 1529times energy-efficiency gain of DOS over CPU.](<https://verace.in/research/diffractive-optical-sorting/figures/performance_plots.webp>)

Figure 2: Comparison of Latency and JouleSort Efficiency Scaling. (a) Shows log-log latency scaling for CPU Quicksort, DOS Simulation, and DOS physical hardware (Est.). (b) Shows semi-log scaling of JouleSort efficiency (Records/Joule) highlighting the $1529\times$ energy-efficiency gain of DOS over CPU.

The empirical evaluation (Table I and Fig. 2) validates the immense scalability of the diffractive approach. By utilizing the sparse representation, the C simulation achieves a speedup of up to $2.40\times$ over CPU Quicksort, even under single-threaded virtual execution. The physical optical hardware implementation (operating at a 100MHz sensor clock) completes sorting and readout for $10^7$ records in just $100\,\text{ms}$, consuming a mere $35.0\,\text{mJ}$ of energy. This represents a SOTA **$1529\times$ energy-efficiency increase** (JouleSort) over traditional silicon CPU sorting, completely bypassing the comparison limit.

## 6. Conclusion

We have proposed Diffractive Optical Sorting (DOS), a novel physical architecture that sorts datasets in $O(1)$ propagation time. By leveraging the physical dispersion of Flint Glass, DOS maps numerical inputs to spatial coordinates without logical comparisons. While limited in sorting capacity by the Abbe diffraction limit and CCD sensor pitch, DOS presents a powerful paradigm shift for specialized low-latency computing hardware.

## References

1. Nyberg, C., & Gray, J. (1994). The Jim Gray Sort Benchmark. Online: http://sortbenchmark.org.
2. Cauchy, A. L. (1836). Mémoire sur la dispersion de la lumière.
3. Lin, X., et al. (2018). All-optical machine learning using diffractive deep neural networks. Science, 361(6406), 1004-1008.
4. Knuth, D. E. (1997). The Art of Computer Programming, Volume 3: Sorting and Searching. Addison-Wesley.
5. Shastri, B. J., et al. (2021). Photonics for artificial intelligence and neuromorphic computing. Nature Photonics, 15(2), 102-114.
6. Caulfield, H. J., & Dolev, S. (2010). Why future supercomputing requires optical computers. Int. Journal of Unconventional Computing, 6(2), 113-127.

## License

[PolyForm Noncommercial License 1.0.0](https://verace.in/license)

This work is open research. Free for any noncommercial use: research, education, personal projects, evaluation, and nonprofit or public-sector use. Commercial use requires a separate license, available by contacting krrish@verace.in.
