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

Institutions

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
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

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

Ashikur Rahman Muhammad
Zenodo (CERN European Organization for Nuclear Research)
Logic, programming, and type systems
article

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

Ashikur Rahman Muhammad
article en

Abstract

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.

Zenodo (CERN European Organization for Nuclear Research)
Green University of Bangladesh (BD)
Openalex Percentile: Top 14%
Logic, programming, and type systems
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon