Complexity of Computations Nicholas Tran Department of Mathematics & Computer Science Santa Clara University Santa Clara, CA USA
How fast can computers add two integers ?
Running Time is measured... In terms of basic operations (digit addition) As a function of input size (number of digits)
A(n) = n (digit additions) a n a n-1 a n-2... a 2 a 1 + b n b n-1 b n-2... b 2 b c n+1 c n c n-1 c n-2... c 2 c 1
Linear Running Time is FAST! Assume: 3GHz processor (3 billion cycles / second) One basic operation = 10 cycles 64-bit words (19 decimal digits) Can add 4.7 million pairs of 64-bit integers in one second!
Is Linear Time Optimal ? Yes! Every bit must be examined
How fast can computers multiply two integers ? 1 2 *
M(n) = n 2 (digit mults) + (n-1)n (digit additions) a n a n-1 a n-2... a 2 a 1 * b n b n-1 b n-2... b 2 b
Quadratic Running Time is OK Assume: 3GHz processor (3 billion cycles / second) One basic operation = 10 cycles Can multiply 300 pairs of 1024-bit integers in one second.
Is Quadratic Time optimal ? No! Divide-and-conquer method: n Fast-Fourier-Transform: n log n
Divide and Conquer Multiplication A 1 a n... a 1+n/2 a n/2... a 1 A 0 B 1 b n... b 1+n/2 b n/2... b 1 B 0 A*B = 2 n (A 1 *B 1 ) + 2 n/2 [(A 1 – A 0 )*(B 0 – B 1 ) + A 1 *B 1 + A 0 *B 0 ] + A 0 *B 0
Running Time M(n) = 3M(n/2) = 3*(3M(n/4)) = 3*3*(3M(n/8)) =... = 3 lg n = n lg 3 = n
Open Question Linear-time algorithm for integer multiplication ?
How fast can computers multiply two matrices ? * =
MT(n) = n 3 (multiplications) Result matrix has n 2 entries Each entry requires n multiplications
Is Cubic Time optimal ? No! Divide-and-conquer method: n Fastest known: n 2.376
Open Question Quadratic-time algorithm for matrix multiplication ?
How fast can computers compute b x ? = \ \ \ \ \ \ \ \ \ \
Naïve algorithm: x multiplications b x = b*b*...*b (x times)
Better algorithm: 2n multiplications (n=lg x) b 21 = b = b 16 b 4 b 1 b b 2 = b*b b 4 = b 2 * b 2 b 8 = b 4 * b 4 b 16 = b 8 * b 8
How fast can computers find gcd(a,b) ? Greatest common divisor of 9 and 6 is 3
Naïve method: min(a,b) divisions Gcd(9, 6): 6 divides 6 but not 9 5 does not divide 6 4 does not divide 6 3 divides 6 AND 9
Euclidean Algorithm: 5*lg min(a, b) gcd(a, b) = gcd(b, a mod b) gcd( ,361) = gcd(361, 190) = gcd(190, 171) = gcd(171, 19) = gcd(19, 0) = 19
gcd(a, b) by factoring into primes 9 = 2 0 * = 2 1 * 3 1 gcd(9, 6) = 2 0 * 3 1
How fast can computers recognize primes ? Isprime(11) = true Isprime(314159) = true Isprime(27183) = fase
Naïve method: √x divisions Theorem: if x = ab, then either a or b is at most √x
Too slow for large x! Largest known prime: – 1 Would take ~ years (age of universe ~ years)
Major Breakthrough Agrawal, Kayal, Saxena published an algorithm in 2004 with running time (lg x) 6 Would take years on the largest known prime!
In practice... Probabilistic algorithm (Rabin) Very fast [(lg x) 2] but may make mistake Would take 40 days on the largest known prime
How fast can computers factor integers ? = 13 * 241 *
Open Question Fastest known algorithm for factoring integers is faster than x but slower than lg x Is there a fast algorithm for factoring integers ?
Major Breakthrough Shor published a (lg x) 3 method for quantum computers in 2001
RSA Cryptography Invented by Rivest, Shamir, Adleman in 1978 Seems unbreakable if there are no fast methods for integer factoring
How RSA works I put on my website two integers (n, e) n is the product of two secret big primes p, q e is chosen so that gcd(e, (p-1)(q-1)) = 1 I compute d so that de = 1 + multiple of (p-1)(q-1)
To send a message x You get (n, e) from my website and send x e (mod n) I decrypt by computing (x e ) d (mod n) = x Unless you can factor n = pq, it seems hard to find d
Example (Stinson) I put on my website (11413, 3533) = 101 * 113 gcd(3533, (100*112)) = 1 d = * 3533 = 1 (mod 11200)
Example (ctd.) To send me 9726, you compute (mod 11413) = 5761 To decode I compute (mod 11413) = 9726
Exploiting Hardness of Pattern Recognition
Even Harder Problems Traveling Salesman: shortest route starting from San Jose through n cities Partition: divide a set of n people into two groups, so that the total weight of each group is identical
NP-hard Problems Solutions are hard to find but easy to check A fast solution to any of these problems would yield a fast solution to integer factoring A one-million dollar prize is currently offered to a resolution of this issue
Summary