Accelerated Knight: An O(1) Algorithm for Computing Minimum Knight Moves on an n × n Chessboard
We present an O(1) time and O(1) space algorithm for computing the minimum number of knight moves between two squares on a finite n × n chessboard. Classical approaches use breadth-first search (BFS) and require O(n^2) time. Our algorithm exploits symmetry, a lowerbound threshold principle, and a parity adjustment to derive a closed-form solution. The only exceptions are a finite set of boundary cases near the corners and on boards of size at most 4×4, which are handled by a small lookup table. We prove correctness via a symmetry reduction, a lower-bound lemma, a complete infinite-board induction, and a finite-board boundary lemma. We validate the algorithm against BFS for all pairs on boards up to 50 × 50 and for random pairs on boards up to 1000 × 1000.
Authors
- Masrur Sarar (ORCID: https://orcid.org/0009-0005-5991-7600)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-10-17
- DOI
- https://doi.org/10.5281/zenodo.23429347
- Primary Topic
- Complexity and Algorithms in Graphs
- Type
- preprint