L3 (Algs with Numbers) Flashcards

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

Two important problems with numbers are Factoring and Primality. What is the premise of these problems?

A

Factoring: Given a number N, express it as a product of prime factors
Primality: Given a number N, determine whether it is a prime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the time complexity of the fastest known factoring algorithm?

A

The fastest known algorithm for factoring is exponential in the number of bits N, O(2^n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Consider the standard “algorithm” for adding binary numbers (addition) x and y with these numbers being n bits long

What is the runtime of this algorithm?

A

The runtime is O(n) to add x and y

Note: For computers, 32 or 64 bit addition is constant time via an ALU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Consider the multiply(x,y) algorithm

If n is the number of bits in x and y, What is the runtime of this algorithm using the naive approach (no FFT or multiDC)?

A

The runtime is O(n^2)

This algorithm can run recursively

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe the multiply(x, y) algorithm for multiplying numbers x and y

What is the base case?

A

x * y = {
2 * (x * floor(y/2)) : if y is even
x + 2 * (x * floor(y/2)): if y is odd
}

The base case is if y = 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

For an algorithm to divide an integer x by an integer y != 0, we have to find two numbers. What are they?

A

Find:
1. find a quotient q
2. find a remainder r < y

Such that x = q * y + r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the formal rule for x modulo N?

A

Given integers x and N, we write x = qN + r where 0 <= r < N is the remainder and then

x mod N = r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If the modulo can be thought of as a function. What would the inputs and outputs be?

A

inputs: integers x and N
outputs: r = the remainder of x divided by N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does it mean for two numbers to be congruent?

A

Two numbers (x and y) are congruent (or equivalent) if they have the name remainder when divided by N. We write:

x ≡ y (mod N)

Which also means x mod N = y mod N

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Congruency states that two numbers have the same remainder:

x ≡ y (mod N)

What can we say about what N divides?

A

If x and y are congruent, then we can say that N divides (x - y) with no remainder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Congruent numbers have a substitution property. If we have:
x ≡ x’ (mod N) and
y ≡ y’ (mod N)

then what can we say?

A

If x ≡ x’ (mod N) and
y ≡ y’ (mod N)

Then
x + y ≡ x’ + y’ (mod N)
and
x*y ≡ x’y’ (mod N)

That is, if (x, x’) are congruent and (y, y’) are congruent then:

  • x + y is congruent to x’ + y’
  • xy is congruent to x’y’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the modulo arithmetic properties for:
- Associativity
- Commutativity
- Distributivity

A

Associativity:
x + (y + z) ≡ (x + y) + z (mod N)

Commutativity:
xy ≡ yx (mod N)

Distributivity:
x(y+z) ≡ xy + y*z (mod N)

ie: The following pairs are congruent:
[x+(y+z), (x+y)+z]
[xy, yx]
[x(y+z), xy+y*z]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Consider two modulo N numbers x and y. Since each number is less than N, the number of bits is n <= log2 (N)

What is the time complexity of:
- Modulo Addition
- Modulo Multiplication

A
  • Modulo Addition: O(n) time
  • Modulo Multiplication: O(n^2) time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly