Skip to content

Conversation

@yadvendra20
Copy link

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".

… some cases in array.h where memory allocation may fail
Copy link
Owner

@moghya moghya left a 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"
Copy link
Owner

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) {
Copy link
Owner

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
Copy link
Owner

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

Copy link
Owner

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

Copy link
Owner

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

Copy link
Owner

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) {
Copy link
Owner

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";
Copy link
Owner

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.

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