Skip to content

Conversation

@Erennn7
Copy link
Contributor

@Erennn7 Erennn7 commented Oct 18, 2025

PR: Karatsuba Multiplication in R

This PR introduces a fully documented implementation of Karatsuba Multiplication in R, a fast recursive algorithm designed for efficient large integer multiplication using the divide-and-conquer approach.

Overview

The karatsuba function implements the Karatsuba multiplication algorithm, which optimizes the standard multiplication process by reducing the number of recursive multiplications.
Instead of performing four sub-multiplications as in the traditional method, Karatsuba’s algorithm performs only three, significantly improving performance for large numeric values.

This approach is especially beneficial for computations involving big integers or high-precision arithmetic, offering better efficiency without sacrificing accuracy.

Complexity

  • Time Complexity: O(n^log₂3) ≈ O(n^1.585)
  • Space Complexity: O(n) due to recursion

Copilot AI review requested due to automatic review settings October 18, 2025 09:05
@Erennn7 Erennn7 requested review from acylam and siriak as code owners October 18, 2025 09:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements Karatsuba multiplication in R with a recursive divide-and-conquer approach and inline usage examples.

  • Adds a karatsuba function for integer multiplication.
  • Includes inline examples and ad-hoc test cases (currently executed on load).

@Erennn7
Copy link
Contributor Author

Erennn7 commented Oct 19, 2025

Implemented improvements based on review feedback and Copilot recommendations.

Changes made:
• ✅ Added input validation and sign handling for negative and non-integer inputs
• ✅ Replaced nchar(as.character(...)) with a numeric-based digit counting function to avoid issues with scientific notation
• ✅ Added execution guard (if (sys.nframe() == 0)) so examples only run when the script is executed directly
• ✅ Expanded function documentation to include input expectations, output type, limitations, and dependencies
• ✅ Verified correctness with test cases and standard multiplication comparisons

These updates enhance robustness, numerical reliability, and documentation clarity.

@Erennn7
Copy link
Contributor Author

Erennn7 commented Oct 20, 2025

@siriak please have a look

Copilot AI review requested due to automatic review settings October 24, 2025 15:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

@siriak siriak enabled auto-merge (squash) October 24, 2025 15:34
@siriak siriak merged commit c763bd7 into TheAlgorithms:master Oct 24, 2025
2 checks passed
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.

2 participants