feat(concepts): Add prefix sum array algorithm - #24
Open
dcq-31 wants to merge 1 commit into
Open
Conversation
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inO(1)time.This version is adapted to the current
mainarchitecture 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
src/lib/algorithms/concepts.tsaddsprefixSumArrayas a concept visualization with bilingual step descriptions viad().src/lib/algorithms/index.tsimports and registers the algorithm under the existingConceptscategory.src/lib/algorithms/catalog.tsandsrc/lib/algorithms/loaders.tsregister the newprefix-sum-arrayid so routes, on-demand loading, and code pages resolve correctly.src/content/algorithms/prefix-sum-array.tsadds English and Spanish long-form descriptions using the current content system.src/lib/visualizers/concept/prefix-sum.tsadds a dedicated visualizer showing the original array, prefix array, active build index, highlighted query range, and query formula.src/lib/types.tsaddsPrefixSumState, andsrc/lib/visualizers/concept/index.tsregisters the newprefixSumconcept renderer for lazy loading.prefix-sum-array.README.mdandREADME_ES.mdare 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:O(n)preprocessing pass in exchange forO(1)range-sum queries.prefix[0] = arr[0], establishing the first known cumulative sum.prefix[i] = prefix[i - 1] + arr[i], while highlighting the current element and the cumulative covered range[0..i].sum(0, r)where the result comes directly fromprefix[r]with no subtraction.sum(l, r) = prefix[r] - prefix[l - 1], highlighting both prefix indices used in the subtraction.The walkthrough intentionally shows both query cases:
sum(0, 2) = prefix[2]sum(1, 4) = prefix[4] - prefix[0]