Skip to content

feat(concepts): Add prefix sum array algorithm - #24

Open
dcq-31 wants to merge 1 commit into
midudev:mainfrom
dcq-31:feature/prefix-sum-array
Open

feat(concepts): Add prefix sum array algorithm#24
dcq-31 wants to merge 1 commit into
midudev:mainfrom
dcq-31:feature/prefix-sum-array

Conversation

@dcq-31

@dcq-31 dcq-31 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Add Prefix Sum Array algorithm to Concepts category

Summary

Adds Prefix Sum Array — the classic preprocessing technique for static range-sum queries — to the existing Concepts / Conceptos category. The algorithm builds an auxiliary array where each position stores the sum of all previous elements, allowing later sum(l, r) queries to be answered in O(1) time.

This version is adapted to the current main architecture and integrated through the existing catalog, dynamic loaders, localized content files, concept visualizer system, and per-language implementation packs so it works with the current app structure.

Changes

  • New algorithm: src/lib/algorithms/concepts.ts adds prefixSumArray as a concept visualization with bilingual step descriptions via d().
  • Registry: src/lib/algorithms/index.ts imports and registers the algorithm under the existing Concepts category.
  • Catalog + loaders: src/lib/algorithms/catalog.ts and src/lib/algorithms/loaders.ts register the new prefix-sum-array id so routes, on-demand loading, and code pages resolve correctly.
  • Localized content: src/content/algorithms/prefix-sum-array.ts adds English and Spanish long-form descriptions using the current content system.
  • Concept visualizer: src/lib/visualizers/concept/prefix-sum.ts adds a dedicated visualizer showing the original array, prefix array, active build index, highlighted query range, and query formula.
  • Types: src/lib/types.ts adds PrefixSumState, and src/lib/visualizers/concept/index.ts registers the new prefixSum concept renderer for lazy loading.
  • Language packs: concept implementation maps for C++, Java, Python, and Rust now include prefix-sum-array.
  • READMEs: README.md and README_ES.md are aligned with the real catalog by adding Prefix Sum Array to Concepts / Conceptos and removing the stale Adjacency Matrix mention from Graphs / Grafos.

Visualization

Trace of a static array [3, 1, 4, 2, 5] shown as a two-row concept visualization:

  1. Intro — frames the tradeoff: one O(n) preprocessing pass in exchange for O(1) range-sum queries.
  2. Initialization — sets prefix[0] = arr[0], establishing the first known cumulative sum.
  3. Build phase: each next step computes prefix[i] = prefix[i - 1] + arr[i], while highlighting the current element and the cumulative covered range [0..i].
  4. Base-case query — demonstrates sum(0, r) where the result comes directly from prefix[r] with no subtraction.
  5. General query — demonstrates sum(l, r) = prefix[r] - prefix[l - 1], highlighting both prefix indices used in the subtraction.
  6. Result — closes by reinforcing why prefix sums are useful for many queries on a static array and why they are not the right tool for dynamic updates.

The walkthrough intentionally shows both query cases:

  • Range starts at zero: sum(0, 2) = prefix[2]
  • General range: sum(1, 4) = prefix[4] - prefix[0]

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

@dcq-31 is attempting to deploy a commit to the midudev pro Team on Vercel.

A member of the Team first needs to authorize it.

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