- Notifications
You must be signed in to change notification settings - Fork20.9k
Optimize power() using exponentiation by squaring (O(log n))#7069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
codecov-commenter commentedNov 15, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #7069 +/- ##========================================= Coverage 78.33% 78.33%- Complexity 6670 6672 +2========================================= Files 753 753 Lines 22185 22192 +7 Branches 4356 4359 +3 =========================================+ Hits 17378 17384 +6 Misses 4107 4107- Partials 700 701 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DenizAltunkapan commentedNov 23, 2025
whats the difference between your implementation andhttps://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/divideandconquer/BinaryExponentiation.java ?@Vinayak-v12 |
This PR optimizes the power() method by replacing the linear recursive
implementation with an exponentiation-by-squaring approach.
✔ Time complexity reduced from O(n) → O(log n)
✔ Handles negative exponents
✔ Keeps same behavior as original implementation
✔ Fully compatible with existing test cases
✔ No API changes
This improves performance and reduces recursion depth while maintaining clean readability.