Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Find the Greatest Common Denominator (GCD) of two numbers

A
Euclid's Algorithm:
GCD(int a, int b) 
{
    if (b == 0) return a;
    return GCD(b, a%b);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find all primes between 1 and N

A
The Sieve of Eratosthenes:
public boolean[] sieve(int n)
{
    prime = new boolean[n+1]
    Arrays.fill(prime,true);
    prime[0]= false;
    prime[1] = false;
    int m = Math.sqrt(n);
for(i=2; i
How well did you know this?
1
Not at all
2
3
4
5
Perfectly