-
Notifications
You must be signed in to change notification settings - Fork 27
Added Number_Theory_Algorithms under include directory #44
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 our terms of service and privacy 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
… some cases in array.h where memory allocation may fail
moghya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @yadvendra20 . Please take a look at the comments.
| #include "include/heap.h" | ||
| #include "include/graph.h" | ||
|
|
||
| #include "include/Number_Theory_Algorithms/fundamental_functions.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change name of directory to be small case
| * More about binary exponentiantion: https://cp-algorithms.com/algebra/binary-exp.html | ||
| */ | ||
|
|
||
| long long binaryExponentiation(long long base, long long exponent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider effects of bits when dealing with small number but not similar data type
| } | ||
|
|
||
| /* | ||
| * Modular binary exponentiation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention details about the algorithms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the reference used to implement this particular algo.
| namespace dsa { | ||
|
|
||
| // returns true if the number is prime otherwise returns false | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove blank line
| } | ||
|
|
||
| // Sieve of eratosthenes | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| * More about sieve of eratosthenes: https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html | ||
| */ | ||
|
|
||
| array<bool> sieve(long long int number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this use some sort of optimisation ? making is_prime static or similar other optimisations ?
maybe a object which can be reset with different limit later that again internally just increases length of array
| capacity=size+spare; | ||
| objs = new type[capacity]; | ||
| if(!objs) | ||
| throw "Memory allocation failed"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to do this across lib. a wrapper around new should be implemented in this, could you please file a ticket for that and we can take it up.
Added some utility functions and algorithms in Number Theory and handled some cases in "array.h" where memory allocation may fail. Also wrote the tests under "tests.h".