Skip to content

Commit

Permalink
Merge pull request #8 from juril33t/master
Browse files Browse the repository at this point in the history
Added description for exponent to readme
  • Loading branch information
Pradyuman7 authored Dec 25, 2018
2 parents 5e4be3d + 481fb30 commit 77c96aa
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ A Java library for people who want to implement some algorithms quickly.
- FindMaxSubArrayProduct
>Find the maximum continuous sub array product in a given array of fixed length and no length constraint.
- Exponent
>Calculate exponents of natural numbers.
***
# How to use
Expand All @@ -48,14 +51,14 @@ This class helps you to find if a number is prime or not, for number upto 1 mill

To use this library, just make an object of this class, and call method `start()` in the beginning of your program. After that, just use `isPrime()` method to find boolean value corresponding to the number which is prime or not.

```
```java
public boolean isPrime(int number){
// returns boolean value stating the number is prime or not
}
```

Example code, for understanding:
```
```java
public static void main(String[] args){

SievePrimesAlgorithm prime = new SievePrimesAlgorithm();
Expand All @@ -72,21 +75,21 @@ This class helps you find number of characters in a String of your choice. You c

To use this library, simply make an object of this class, and call `findNumOccurencesOfCharacter( myString, myCharacter)` to find number of occurences of `myCharacter` in `myString`. You can also use the method `findNumOccurencesOfAllCharacters(myString)` to get number of occurences of all characters present in `myString`.

```
```java
public int findNumOccurencesOfCharacter(String myString, char myCharacter){
// returns int stating the number of occurences of myCharacter in myString
}
```

```
```java
public void findNumOccurencesOfAllCharacters(String myString){
// prints number of occurences of each character
}
```

Example code, for understanding

```
```java
public static void main(String[] args){

NumOccurencesOfCharacters nm = new NumOccurencesOfCharacters();
Expand All @@ -104,15 +107,15 @@ This class finds all the divisors of the number of your choice in O(n) time, the

To use this class, just make a simple object of `Divisors` class and call `findDivisors()` method which returns you an `ArrayList<Integer>` which contains all the divisors of the number in ascending order.

```
```java
public ArrayList<Integer> findDivisors(int number){
// returns ArrayList of all the divisors of the number sorted in ascending order
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

Divisors d = new Divisors();
Expand All @@ -128,15 +131,15 @@ Sometimes using Sieve's algorithm is much more redundant and we need a quick and

To use this class, just make a simple object of `CheckPrime` class and call `checkPrime()` method which returns you an `boolean` value corresponding to the number.

```
```java
public boolean checkPrime(long number){
// returns true if the number is prime, otherwise fase
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

CheckPrime cp = new CheckPrime();
Expand All @@ -152,15 +155,15 @@ Getting the sum of squares of divisors of a number is getting too much common in

To use this class, just make a simple object of `GetDivSquareSum` class and call `sumDivSquare()` method which returns you an `long` value corresponding to the sum of the square of the divisors of the number of your choice.

```
```java
public long sumDivSquare(int num){
// returns sum of squares of the divisors of the num
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

GetDivSquareSum gd = new GetDivSquareSum();
Expand All @@ -176,15 +179,15 @@ Searching for a particular number's existence in an array has always been one of

To use this class, just make a simple object of `BinarySearch(int[] array)` class and call `search()` method which returns you the boolean value stating the value exists in the array or not.

```
```java
public boolean search(int num){
// returns true or false depending on the existence of the number in the array
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

int[] arr = {1,5,3,14,2,12,7,6};
Expand All @@ -202,15 +205,15 @@ Searching for a maximum sum of continuous sub-arrays in a given array is fastly

To use this class, just make a simple object of `MaxSubArraySum(int[] array)` class and call `getSum()` method which returns you the int value (taking into account for positive and negative numbers) corresponding to the maximum sum of subarrays in your given array.

```
```java
public boolean getSum(){
// returns maximum continuous sub-array sum for your desired array
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

int[] arr = {1,-2,3,-2,5};
Expand All @@ -228,23 +231,23 @@ Searching for a maximum product of continuous elements of an array is also very

To use this class, just make a simple object of `FindMaxSubArrayProduct(int[] array)` class and call `findMaxProduct()` method which returns you the max sub array product for the whole array.

```
```java
public boolean findMaxProduct(){
// returns maximum continuous sub-array product for your desired array
}
```

There is also another method which lets you find maximum product of `k` element subarrays in your array. It's structure looks like this:

```
```java
public boolean findMaxProduct(int k){
// returns maximum continuous sub-array of length k product for your desired array
}
```

Example code, for understanding:

```
```java
public static void main(String[] args){

int[] arr = {1,-2,3,-2,5};
Expand All @@ -258,6 +261,22 @@ public static void main(String[] args){
}
```


- **Exponent**

This class offers some static methods, offering ways to calculate the n'th power of a number. Usage is rather trivial as shown below:

```java
public static void main(String[] args){

System.out.println(Exponent.modExp(2163, 1231, 32)); // 27, runs in <1 ms on my machine

}
```

The most interesting utility function offered is the `modExp` function, because it can calculate powers to a certain modulus in constant time.


**New additions will be on roll, keep a look out :)**


0 comments on commit 77c96aa

Please sign in to comment.