Skip to content

feat(divide-and-conquer): Add binary exponentiation algorithm - #14

Open
dcq-31 wants to merge 1 commit into
midudev:mainfrom
dcq-31:feat/add-binary-exponentiation
Open

feat(divide-and-conquer): Add binary exponentiation algorithm#14
dcq-31 wants to merge 1 commit into
midudev:mainfrom
dcq-31:feat/add-binary-exponentiation

Conversation

@dcq-31

@dcq-31 dcq-31 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Add Binary Exponentiation algorithm to Divide and Conquer category

Summary

Adds Binary Exponentiation — the classic O(log n) fast-power algorithm — to the existing Divide and Conquer / Divide y vencerás category, which previously contained only Tower of Hanoi. Computes aⁿ by halving the exponent at each recursive step, visualized through the call stack concept so the logarithmic recursion depth is immediately visible.

This version is adapted to the current main architecture instead of the original older branch layout. The algorithm is wired through the catalog, dynamic loaders, localized content files, and per-language implementation packs so it works with the current app structure.

Changes

  • New algorithm: src/lib/algorithms/divide-and-conquer.ts adds binaryExponentiation using the concept / callStack visualization and bilingual step descriptions via d().
  • Registry: src/lib/algorithms/index.ts imports and registers the algorithm under the existing Divide and Conquer category.
  • Catalog + loaders: src/lib/algorithms/catalog.ts and src/lib/algorithms/loaders.ts register the new binary-exponentiation id so routes, on-demand loading, and code pages resolve correctly.
  • Localized content: src/content/algorithms/binary-exponentiation.ts adds English and Spanish long-form descriptions using the current content system.
  • Language packs: divide-and-conquer implementation maps for C++, Java, Python, and Rust now include binary-exponentiation.
  • READMEs: Adds Binary Exponentiation to the Divide & Conquer / Divide y vencerás sections in both README.md and README_ES.md. Also adds the previously omitted Bucket Sort entry to the Sorting / Ordenamiento sections — Bucket Sort was already implemented and registered but had not been listed in the READMEs.

Visualization

Trace of binPow(2, 10) = 1024 shown as an animated call stack:

  1. Intro — frames the problem and the O(log n) idea.
  2. Descent: each recursive call halves the exponent (10 → 5 → 2 → 1 → 0), showing the stack grow one frame at a time.
  3. Base case at binPow(2, 0): returns 1.
  4. Ascent: each frame resolves using either the even-exponent case (half × half) or the odd-exponent case (half × half × base).
  5. Result: 2¹⁰ = 1024, demonstrating logarithmic recursion depth instead of linear repeated multiplication.

The same trace shows both cases naturally:

  • Even exponent: binPow(2, 2) and binPow(2, 10)
  • Odd exponent: binPow(2, 1) and binPow(2, 5)

@vercel

vercel Bot commented May 25, 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.

@dcq-31
dcq-31 force-pushed the feat/add-binary-exponentiation branch from 400532d to 492d798 Compare August 2, 2026 02:35
@dcq-31 dcq-31 changed the title feat: Add binary exponentiation algorithm feat(divide-and-conquer): Add binary exponentiation algorithm Aug 2, 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