Algo-Phantoms / Algo-Tree

Algo-Tree is a collection of Algorithms and data structures which are fundamentals to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. It contains solutions in various languages such as C++, Python and Java.
MIT License
363 stars 617 forks source link

Modular Exponentiation #241

Open Nkap23 opened 3 years ago

Nkap23 commented 3 years ago

Modular exponentiation is used to compute pow(n1,n2)%mod (n1^n2%mod) in log(n2) time!

This algorithm computes pow(n1,n2) in log(n2). The normal algorithm would take O(n2) times. This O(n2) is not feasible when n2 is larger than 10^7 or 10^8. So this algorithm is a must when dealing with large numbers!

I believe this algorithm is one of the basic yet one of the most used algorithms used. I want to contribute and add this algorithm to this repo, so in the future newcomers can refer to it and understand it.

I request Project Admins/Mentors to assign the issue to me. @tarun26091999

Edit: PR: https://github.com/Algo-Phantoms/Algo-Tree/pull/293

tarun26091999 commented 3 years ago

Modular exponentiation is used to compute pow(n1,n2)%mod (n1^n2%mod) in log(n2) time!

This algorithm computes pow(n1,n2) in log(n2). The normal algorithm would take O(n2) times. This O(n2) is not feasible when n2 is larger than 10^7 or 10^8. So this algorithm is a must when dealing with large numbers!

I believe this algorithm is one of the basic yet one of the most used algorithms used. I want to contribute and add this algorithm to this repo, so in the future newcomers can refer to it and understand it.

I request Project Admins/Mentors to assign the issue to me. @tarun26091999

go ahead with CPP

Nkap23 commented 3 years ago

Thank you for assigning. I followed the contributions rules and made a PR for the code! https://github.com/Algo-Phantoms/Algo-Tree/pull/293

Request you to review it!

khushboojoshi3 commented 3 years ago

I would like to work on this issue in C++, please assign it to me.

Deepaliiii commented 3 years ago

I would like to work on this issue in c++, please assign it to me.

shahina-bano commented 3 years ago

I would like to work on this issue in Java. Kindly assign it to me @raksha009

yashmita commented 3 years ago

I would like to work on this issue in Python. Kindly assign it to me @plazzy99