Graph Search and Analysis Flashcards
Graph Search
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
Graph Search Algorithm
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
Big-O Notation
f(n) = O(g(n))
if f(n) = O(g(n)) then for a constant C, f(n) is strictly less than or equal to C(g(n))
Big OMEGA Notatio
f(n) = OMEGA(g(n))
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))
Big-THETA Notation
f(n) = THETA(g(n))
if f(n) = THETA (g(n)) then
Factoring
Given a number N, express it as a product of its prime factors
Primality
Given a number N, determine whether it is a prime.
Different ways of understanding log N
- log N is the power to which you need to raise 2 in order ot obtain N
- The number of times you need to divide by 2 or halve N to get down to 1.
- It is the number of bits in the binary representation of N
- It is the depth of the complete binary tree with N Nodes
- It is the sum 1 + 1/2 + 1/3 +….. + 1/N to within a constant factor
When answering most questions in this class remember that …
the answer should be expressed as a function of the size of the input.
We are constantly wondering “if there is anything better”
In terms of how to improve the runtime of the algorithm
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
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.
Bit shifting (padding a 0 to the right) is a simple way of multiplying the value by the bast.
By bit shifting binary, we double or multiply by 2 the current value of the binary sequence.
Questions to ask about any algorithm
IS this algorithm correct?
How long does the algorithm take?
Can we do better?
Modular Arithmetic
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.
Equivalence classes
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
Substitution Rule
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)
Two’s Complement
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
For cryptography, modular exponentiation and greatest common divisor will be key
GCD and modular exponentiation
In order to make sure numbers that are being handled/computed never grow too large, we performa intermediate computations modulo N
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)
Euclid’s Algorithm for greatest common divisor
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)
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
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.
For any positive integers, a and b, the extended Euclid algorithm returns integers x, and y such that gcd(a,b) = d = ax+by.
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)
Exmaple of Euclids algorithm and lemma
compute gcd(25,11)
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
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
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-33 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