Graph Search and Analysis Flashcards

1
Q

Graph Search

A

Many graph algorthms use the same basic framework to navigate through a graph. We will call this algorithm: Graph Search

Shows which vertices can be retrivable from a certain vertex

Can be undirected or direct graph

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

Graph Search Algorithm

A

Instance: a graph G(V,E)

Instance: Starting Vertex s

Output: a list of all vertices reachable from s by a directed path in G

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

Big-O Notation

f(n) = O(g(n))

A

if f(n) = O(g(n)) then for a constant C, f(n) is strictly less than or equal to C(g(n))

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

Big OMEGA Notatio

f(n) = OMEGA(g(n))

A

if f(n) = OMEGA (g(n)) then g(n) = O(f(n)) where for a constant C, g(n) is strictly less than or equal to C(f(n))

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

Big-THETA Notation

f(n) = THETA(g(n))

A

if f(n) = THETA (g(n)) then

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

Factoring

A

Given a number N, express it as a product of its prime factors

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

Primality

A

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
8
Q

Different ways of understanding log N

A
  1. log N is the power to which you need to raise 2 in order ot obtain N
  2. The number of times you need to divide by 2 or halve N to get down to 1.
  3. It is the number of bits in the binary representation of N
  4. It is the depth of the complete binary tree with N Nodes
  5. It is the sum 1 + 1/2 + 1/3 +….. + 1/N to within a constant factor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When answering most questions in this class remember that …

A

the answer should be expressed as a function of the size of the input.

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

We are constantly wondering “if there is anything better”

A

In terms of how to improve the runtime of the algorithm

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

It is often useful to remember that while for small values of n studying algorithms seems trivial but we are interested in how theese algorithms do for large values of n

A

By studying in detail at the level of the elementary operations on the indiviudal bits, it can uncover how the hardware, transtiors and wires, are manipulated for the implemntation of the algorithm.

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

Bit shifting (padding a 0 to the right) is a simple way of multiplying the value by the bast.

A

By bit shifting binary, we double or multiply by 2 the current value of the binary sequence.

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

Questions to ask about any algorithm

A

IS this algorithm correct?

How long does the algorithm take?

Can we do better?

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

Modular Arithmetic

A

System for working with restricted ranges of integers

x modulo N is the remainder when x is divided by N, or x =qN + r, 0 =< r less than N, then x modulo N is equal to r.

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

Equivalence classes

A

For example, three equivalence classes of modulo 3 any member of an equivalence class is substitutable for any other; when the numbers 5 and 11 are no different. 0 class, 1 class, and 2 class are equivalent to the next class of remainders that are 0 , 1, and 2

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

Substitution Rule

A

Using Associativity, commutativity, and Distributivity, together with the subsitution rule, implies that while performing arithmetic operations, it is legal to reduce intermediate results to their remainder modulo N at an stage.

For example: 2^{354} = 2{5(69)} = 32^{69} = 1^{69} = 1 (mod 31)

17
Q

Two’s Complement

A

Modular arithmetic is well demonstrated by 2’s complement used to storing signed integers. It is used to represent numbers in the range [-2^{N-1} , 2^{N-1}-1]

Positive integers will have a leading 0 in the sequence.

Negative integers will have a leading 1 in the sequence. Negative numbers are constructed by first flipping all the bits and then adding 1 to the right most position

Essentially its -2^{N-1} -x

18
Q

For cryptography, modular exponentiation and greatest common divisor will be key

A

GCD and modular exponentiation

19
Q

In order to make sure numbers that are being handled/computed never grow too large, we performa intermediate computations modulo N

A

So for x^y mod N, we take advantage of properties of log to break up x^y as a product of x^{a_2) * x^{b_2) * x^{c_2) …. * x^{z_2) , which can be the binary sequence of the factors of y matching the preferred base (in this case 2)

20
Q

Euclid’s Algorithm for greatest common divisor

A

Euclid’s rue: If x and y are positive integers with x greater than or equal to y, then gcd (x,y) = gcd (x mod y, y)

Any integer that divides both x-y and y must also divide x and y , so gcd ((x,y) greater than or equal to gcd (x-y, y)

21
Q

Suppose d is the gcd (a,b). How do you prove/check this? Need to confidently know that the factor dervied is the LARGEST/GREATEST

A

If d divides both a and b, and d=ax+by forsome integers x and y, then d = gcd (a,b)

By first two conditions, d is a common divisors of a and b, so it cannot exceed the actual gcd. Thus d must be less than or equal to gcd(a,b). On the other hand, the result of gcd(a,b) must be a common divisor of a and b, so it must divide ax + by =d. This implies that gcd(a,b) less than or equal to d. Putting together everything d=gcd(a,b)

Under any circumstane gcd(a,b) can always be expressed in this checkable form.

22
Q

For any positive integers, a and b, the extended Euclid algorithm returns integers x, and y such that gcd(a,b) = d = ax+by.

A

Ignoring x and y, the expression/equation is the same as previous equation. So still need to always compute d = gcd(a,b) to start.
next use recursive nature of algorithm to hint at using induction. When b=0, algorithm ends. So use induction with b.

Base case b=0. Then continue with induction for values of b greater than 0. gcd (a,b) is gcd (b, a mod b). Since a mod b < b, we can apply inductive hypothesis to this recursive call and conclude that x’ and y’ returned are correct. Thus:

gcd (b,a mod b) = bx’ + (a mod b) y’

(not complete)

23
Q

Exmaple of Euclids algorithm and lemma

compute gcd(25,11)

A
25 = 2 * 11 + 3
11 = 3 * 3 + 2
3 = 1 * 2 + 1
2 = 2 * 1 + 0

At each stage, the numbers (11, 3, 2, 1) are reduced smaller and smaller. Thus

gcd(25,11) = gcd (11,3) = gcd(3,2) = gcd (2,1) = gcd(1,0) =1

24
Q

Moving backwards from the example of finding gcd(25,11). Given (2,1) then (3,2) then (11,3) then (25,11), find x and y such that 25x + 11y = 1

Show how to reconstruct

A

1= 1 - 0

1 = 2 - (2 -2*1) = -1 *2 + 3 * 1
Using substitution

1 = -1 2 + 3 * (3 - 1 * 2) = 3 * 3 - 4 * 2
Continue substitution 2= 11-3
3 and 3 = 25 -2*11

1 = 3 * 3 - 4 * (11 - 3 * 3) = -4 *11 + 15 * 3 =
-4 * 11 + 15 (25 - 2 * 11) = 15 * 25 - 24 * 11

Now we get:
15 * 25 - 24 * 11 = 1, So x =15, y = -34

25
Q

Modular Division

axiom: Every number a (a != 0) has an inverse , 1/a and dividing by a is the same as multiplying by the inverse.

In modular arithmetic we do something similar too. -a and a

x is Multiplicative inverse of a modulo N if ax = 1 (mod N)

A

There can be at MOST one such x modulo N., and that is dneoted as a^{-1} . Though inverse doesn’t always exist.

For example:
2x != 1 mod 6 for any x. Since a and N are both even and thus a mod N is always even, since a mod N = a - kN for some k. We can be certain that gcd(a,N) divide ax mod N

26
Q

The only case that a is not invertible is when gcd (a, N) =1 (we say a and N are relatively prime), the extended Euclid algorithm gives us integers x and y such that ax + Ny =1. This means ax = 1(mod N)

A

Example: Suppose you need to compute 11^{-1} mod 25. Using extended Euclid Algorithm, we find 1525 - 3411 =1. Reducing both sides modulo 25, we have -34 = 16 mod 25 is the inverse of 11 mod 25

27
Q

Modular Remainder Theorem

For any a mod N, a has a multiplicative inverse modulo N if and only IF it is relatively prime to N.

A

If this inverse exists it can be found in O(n^3), where n is the number of bits of N through Extended Euclid Algorithm (EEA)

This resolves issue of modular division: when working modulo N, we can divide by numbers relatively prime to N and only by these . And to actually carry out the division, we multiply by the inverse.

28
Q

Factoring is HARD and Primality is EASY

A

We cannot factor large numbers but can easily test huge numbers for primality !

29
Q

Trick to cut down number of integers to check.

A

1) Even numbers are never prime
2) You can declare N prime if you test all the numbers up to sqrt (N) . Since if N can be factored as N = K * L then it is impossible for both to be greate than sqrt(N)

30
Q

Primality Testing

first explore Fermats Little Theorem:
if p is prime, then for every a greater than or equal to 1 and a less than p:

a^{p-1} = 1 mod (p)

A

Suppose that S is the set of all integers modulo p, that is S= {1, 2, … p-1}. Notice that by multiplying the set S by a (modulo p) jsut permutes (shuffles ) them.

Multiplying both sides of equation by (p-1)! we get:
S = {3 1 mod7, 32 mod7, …. 3*6 mod 7}
Now multiplying all the numbers in each representation then gives

6! = 3^6 * 6! (mod 7)

Divide by 6! we get

3^6 = 1 (mod 7), which is the desired outcome of a=3 and p=7

31
Q

Formal explanation of Fermats Little Theorem

A

S = {1, 2, .. p-1}

We will show that all elements of S are multiplied by a modulo p, and the resulting numbers are all distinct and nonzero. Since they lie in the range [1,p-1] they are just permutations of S.

ai mod p are distinct since IF ai = aj (mod p), then dividing both sides by a gives i = j (mod p) . They are nonzero becuase a i = 0 similiarly implies i =0 . And we can divide by a,because by assumption it is a nonzero and therefore relatively prime to p.

S = {1,2,.. p-1} = {a1 mod p, a2 mod p…, a*(p-1) mod p}

Multiply together its elements in each of the representations to get:

(p-1)! = a^{p-1} * (p-1)! (mod p)

Divide both sides by (p-1)! , which is allowed since p is assumed to be relatively prime , gives the theorem.

32
Q

Fermat’s Little Theorem suggests a “factorless” test for determining whether a number N is prime.

(loook at page 35 for diagram)

  1. pick some a.
  2. Use Fermat’s test : is a^{N-1} = 1 mod N}?????
  3. a) IF pass then its PRIME
    b) if fail , then composite
A

Problem is however, that the theorem is NOT an -f-and only-if condition; it doesn’t say what happens when N is NOT prime.

33
Q

LEMMA: If a^{N-1} != 1 mod N for some a relatively prime to N, then it must hold for at least half of the choices of a < N.

A

….