An In-Place Dual-Pointer Algorithm for Infix-to-Prefix Conversion with O(1) Auxiliary String Space: Formal Safety Proof and 40,000-Case Empirical Validation
Converting an arithmetic expression from Infix to Prefix (Polish) notation is a foundational operation in compiler front-ends, calculator firmware, and data-structures education. The canonical textbook method reduces the problem to an Infix-to-Postfix (Reverse Polish Notation) conversion by executing a three-pass pipeline: reverse the input string, run Dijkstra's Shunting-Yard algorithm into an auxiliary output buffer, and reverse the result. This pipeline performs at least three full string sweeps and requires an O(N) auxiliary output buffer. This paper proposes an alternative designed for memory-constrained systems: the infix string is converted directly into its prefix form within the original character buffer using a dual-pointer, right-to-left scan, requiring zero auxiliary string bytes (O(1) auxiliary string space). The design makes three non-obvious contributions: (i) an operator-associativity inversion rule that renders the backward scan correctness-preserving; (ii) a formal safety invariant—read_idx <= write_idx at every write—which guarantees no character is overwritten before it has been read; and (iii) a fail-soft architecture in which even malformed input cannot corrupt memory. Validated across 40,000 randomized expressions (nesting depth <= 5), Tier 1 reports 100.0000% agreement (0 disagreements), Tier 2 reports 0 corruption and 0 underflow events, and Tier 3 reports 30,509/30,509 semantic matches (0 failures). Complete reference implementation, pseudocode, worked traces, and proofs are included.
Authors
- Ashikur Rahman Muhammad
Institutions
- Green University of Bangladesh (BD)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-10-26
- DOI
- https://doi.org/10.5281/zenodo.23657543
- Primary Topic
- Logic, programming, and type systems
- Type
- article
- Field-Weighted Citation Impact
- 0.00