Skip to content

Validate the network with the time complexity O(L・φ^N) #16

@mizar

Description

@mizar

Let the number of inputs be $N$ and the number of comparators be $L$.

It is well known that the 0-1 principle allows the verification of networks with a computational complexity of $O(L\cdot 2^N)$,

With an ingenious implementation, this can be achieved with a computational complexity of $O(L\cdot\varphi^N)$, where $\varphi$ is the golden number $\varphi=\dfrac{1+\sqrt{5}}{2}\simeq 1.618$.

This is due to the fact that the number of branches in the search tree is a Fibonacci number $\mathrm{Fib}(N+1)=\left\lfloor\dfrac{\varphi^{N+1}}{\sqrt{5}}+\dfrac{1}{2}\right\rfloor$.

The following is a paper (in Japanese) describing this algorithm:

Here is an example implementation in Python:

See also the probrem of competition programming "Verification of Sorting Network" (in Japanese):

This is a demonstration video of a fast N=40 verification using multi-threading. (Executed on Tauri)

sortingnetwork-tauri-app.2025-03-05.23-54-31.mp4

Note, however, that this method is useful when $N$ is large, but when $N$ is small, the $O(L\cdot 2^N)$ method with SIMD is faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions