


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Torng; Class: Design & Theory of Algorithms; Subject: Computer Science & Engineering; University: Michigan State University; Term: Unknown 1989;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Lecture 6 Divide-and-Conquer Algorithms Quicksort Algorithm and Multiplication/Exponentiation Problems Quicksort Algorithm Choose a partition element Partition list of elements into smaller and larger lists Recurse on smaller and larger lists Running time analysis T(n) = T(smaller) + T(larger) + (n) Best-case: T(smaller) and T(larger) are both T(n/2) T(n) = 2 T(n/2) + (n) T(1) = 1 Apply master theorem to see result as (n log n) Worst-case: T(smaller) or T(larger) = T(n-1) [other is T(0)] T(n) = T(n-1) + (n) Applying inhomogeneous equation approach, we get root=1 with mult. 3 This leads to an (n^2 ) complexity This can also be observed by unrolling the recurrence Average-case analysis? Assumptions: All items are distinct Number of comparisons needed to partition array is n- All permutations are equally likely t(n) = n-1 + 1/n[i=1 to n t(i-1) + t(n-i)] for n >= 1 t(0) = 0 i=1 to n t(n-i) = t(n-1) + t(n-2) + … + t(0) = i=1 to n t(i-1) t(n) = n-1 + 2/n k=0 to n-1 t(k) Constructive induction or clever manipulation leads to (n log n) result Can we modify how quicksort chooses its partition element to guarantee that we get (n log n) behavior in the worst case?
Matrix Multiplication How many operations are needed to multiply two 2 by 2 matrices? Traditional approach 8 (two-number) multiplications and 4 additions Strassen’s approach (1969) 7 (two-number) multiplications and 15 additions/subtractions (See problem 7.22) How does this change things for multiplying n by n matrices? Lets assume that n is a power of 2. Traditional approach n^3 two-number multiplications n^3 – n^2 two-number additions Complexity is (n^3 ) Divide-and-conquer approach T(n) = 7 T(n/2) + 18 matrix additions of matrices of dimension n/ = 7 T(n/2) + 18 (n^2 /4)
What is the time required by this approach? T(m,n) <= 0 if n = 1 <= T(m,n/2) + M(mn/2, mn/2) if n is even <= T(m,n-1) + M(m, (n-1)m) otherwise Combining both cases together: T(m,n) <= T(m, floor(n/2)) + M(m floor(n/2), m floor(n/2)) + M(m, (n-1)m) Problem 7.29: This evaluates to O(mana) assuming M(q,s) = (sqa-1) Direct multiplication: a = 2 D-and-C multiplication: a = lg 3 Lower bound argument: afloor(n/2)afloor(n/2)^ : M((m-1)n/2, (m-1)n/2) = (((m-1)(n/2))a) = (mana) Good summary table on bottom of pg 246 It is interesting to note that the D-and-C exponentiation algorithm gains little unless the D-and-C multiplication algorithm is also used. Iterative version of this algorithm is given on pg. 247. Exponentiation with modular arithmetic xy mod z = [(x mod z) times (y mod z)] mod z xy^ mod z = (x mod z)y^ mod z With modular arithmetic, all multiplications can be treated as essentially unit cost operations Thus, we see that D-and-C modular exponentiation requires only (log n) multiplications The direct approach requires n-1 such multiplications Application to public-key cryptography: Alice is sending a message m to Bob Bob does the following first Chooses two 100-digit prime numbers p and q Computes z = pq Computes = (p-1)(q-1) Chooses n uniformly at random from 1 to z- Computes the unique number s between 1 and z-1 such that ns mod = 1 Problem 7.31 describe how to compute s If no such s can be found, then must choose another n Key property of n is that n must have no common factors with Bob no longer needs (p, q, ) for any more computations Bob publishes z and n but keeps s (and p, q, ) secret Alice encrypts her message m to Bob as follows: Assume m can be represented as a number between 0 and z- Alice compute c = mn^ mod z Bob decrypts message m as follows Bob computes cs^ mod z = (mn^ mod z)s^ mod z = (mn)s^ mod z = (mns) mod z = m because of the following result from number theory mx^ mod z = m if 0 <= m <= z-1 AND x mod = 1 What does an eavesdropper who intercepts c and has n and z do? Needs to compute the nth root of c mod z; no efficient solution is known Best known approach Factor z into p and q, Compute as (p-1)(q-1), compute s, then proceed as Bob did No efficient algorithm is known for factorization