Skip to content

Fix #39 space items: in-place sorts, rolling rows, iterative trees - #44

Closed
m-hu wants to merge 1 commit into
masterfrom
fix/39-space-complexity
Closed

m-hu wants to merge 1 commit into
masterfrom
fix/39-space-complexity

Conversation

@m-hu

@m-hu m-hu commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Part of #39 — the seven space-complexity items, same time class with
strictly smaller footprints.

Changes

  • sort/three_way_quicksort/solution and
    sort/three_way_string_quicksort/solution: 3 filterv copies/level →
    in-place 3-way partition on hinted arrays with explicit smaller-first
    stack, O(log n) aux (deep-prefix 2k strings: 3.0s → 0.5s).
  • math/approximation/mult_weights/mult_weights: deleted the T-by-n
    gain matrix, indexes flat vals directly (2500×2500 outputs identical).
  • combinatorics/stirling_bell/stirling_bell: full assoc-in table →
    rolling two-row recurrence.
  • compiler/attribute_grammar: n-node map tree + synth recursion →
    Horner fold (3M-bit input: old OOM after 4.7s vs fast 0.4s).
  • data_structure/bst_lca/...: recursive insert → iterative
    explicit-path descent + bottom-up rebuild (sorted-20k: old
    StackOverflow vs correct).
  • data_structure/red_black_tree/solution: recursive insert-node →
    iterative insert with explicit path + bottom-up fixup (sorted-100k
    identical; delete path intentionally left recursive — insert/fixup
    scope only).

Validation

  • 40/40 before/after checks pass via JVM clojure.main, each with an
    independent python oracle or identical-failure assertion (incl. -Xmx
    heap-limited runs). Pre-existing quirks (quicksort negative parse,
    stirling long overflow) preserved byte-identically. Shared GPG cases
    unavailable locally — CI covers them.

AI-Tool: Muse Code (Meta Muse Spark)

- sort/three_way_quicksort: in-place 3-way quicksort on long-array with
  explicit stack (smaller side first, O(log n) depth); no 3 filterv
  copies per level. Avg O(n log n) time kept.
- sort/three_way_string_quicksort: same in-place 3-way scheme on an
  object array with depth-tagged stack entries.
- math/approximation/mult_weights: index the flat gain vector directly
  instead of building a T-by-n gain matrix. O(T n) time kept.
- combinatorics/stirling_bell: rolling two-row DP (stirling-row) instead
  of the full (n+1)x(k+1) table with assoc-in. O(n k) time kept.
- compiler/attribute_grammar: Horner fold over the bitstring instead of
  building an n-node map tree plus O(n) synth recursion. O(n) kept.
- data_structure/bst_lca: iterative insert via explicit descent path with
  bottom-up rebuild; duplicates still go right. O(h) per insert kept.
- data_structure/red_black_tree: iterative LLRB insert with explicit path
  and bottom-up balance fixup (duplicates balance on the way up, as
  before); root recolored black. O(log n) insert kept.

AI-Tool: Muse Code (Meta Muse Spark)
@m-hu

m-hu commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #45 — all four area branches merged into one batch PR.

@m-hu m-hu closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant