This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int findGCD(int a, int b){ | |
if(a==0) | |
return b; | |
return findGCD(b%a,a); | |
} | |
public static int findLCM(int a, int b){ | |
return a*b/findGCD(a,b); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.idey.algo.math; | |
import java.util.BitSet; | |
public class PrimeNumber { | |
private BitSet bitSet; | |
private int upperLimit; | |
public PrimeNumber(int upperLimit) { | |
this.upperLimit = upperLimit+1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class BreadthFirstIterator<T> implements Iterator<T> { | |
private Set<T> visited = new HashSet<>(); | |
private Queue<T> queue = new LinkedList<>(); | |
private Graph<T> graph; | |
public BreadthFirstIterator(Graph<T> g, T startingVertex) { | |
if(g.isVertexExist(startingVertex)) { | |
this.graph = g; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator; | |
import java.util.NoSuchElementException; | |
public class BinaryNumberGeneratorIterator implements Iterator<String> { | |
private final int size; | |
private final int bit; | |
private int currentBitPostion; | |
public BinaryNumberGeneratorIterator(int bit) { | |
assert(bit<=31); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
public class Singleton implements Serializable { | |
private static volatile Singleton object; | |
private Singleton() { | |
} | |
public static Singleton getInstance() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Range<T extends Comparable<T>> implements Comparable<Range<T>> { | |
private T lower; | |
private T upper; | |
public Range(T lower, T upper) { | |
assert(lower!=null && upper!=null && upper.compareTo(lower)>0); | |
this.lower = lower; | |
this.upper = upper; | |
} | |
//Asummption they are no overlapping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int findingNthFibo(int n, int start, int end){ | |
if(n==1){ | |
return start; | |
}else if (n==2){ | |
return end; | |
}else{ | |
return findingNthFibo(n-1,start,end)+findingNthFibo(n-2, start,end); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int tailRecursiveFibonacii(int n, int end, int start){ | |
return n==1 ? start :tailRecursiveFibonacii(n-1,end+start,end); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FibonacciIterator implements Iterator<Integer>{ | |
private Integer start; | |
private Integer end; | |
private int number; | |
private Integer upperLimit; | |
private Integer nextNumber; | |
public FibonacciIterator(Integer start, Integer end, Integer upperLimit) { | |
if(start<=end && end<=upperLimit){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.idey.algo.iterator; | |
import java.util.*; | |
/** | |
* This class return common intersection elements from N Iterator with Sorted Elements | |
* @param <T> | |
*/ | |
public class IntersectionIterator<T extends Comparable<T>> implements Iterator<T>{ | |
private Iterator<T>[] iterators; |