Arithmetic.

Slides:



Advertisements
Similar presentations
A simple example finding the maximum of a set S of n numbers.
Advertisements

Section 4.1: Primes, Factorization, and the Euclidean Algorithm Practice HW (not to hand in) From Barr Text p. 160 # 6, 7, 8, 11, 12, 13.
More on Divide and Conquer. The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving.
Number Theory and Cryptography
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture.
Lecture 30 CSE 331 Nov 8, HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR.
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Recurrences. What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the.
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Congruence of Integers
CSC 3323 Notes – Recurrence Relations Algorithm Analysis.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Lecture 3.2: Public Key Cryptography II CS 436/636/736 Spring 2012 Nitesh Saxena.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006 Lecture 18March.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
Divide-and-Conquer 7 2  9 4   2   4   7
Section 4.3: Fermat’s Little Theorem Practice HW (not to hand in) From Barr Text p. 284 # 1, 2.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
CS223 Advanced Data Structures and Algorithms 1 Sorting and Master Method Neil Tang 01/21/2009.
Project 2 due … Project 2 due … Project 2 Project 2.
Modular Arithmetic Shirley Moore CS4390/5390 Fall September 3, 2013.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Chinese Remainder Theorem Dec 29 Picture from ………………………
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
7.3 Divide-and-Conquer Algorithms and Recurrence Relations If f(n) represents the number of operations required to solve the problem of size n, it follow.
Fermat’s Little Theorem The RSA Cryptosystem will require exponentiation to decrypt messages. Exponentiation Notation Example 1: Compute Exponentials Example.
Dan Boneh Intro. Number Theory Arithmetic algorithms Online Cryptography Course Dan Boneh.
CSE 311: Foundations of Computing Fall 2013 Lecture 11: Modular arithmetic and applications.
May 9, 2001Applied Symbolic Computation1 Applied Symbolic Computation (CS 680/480) Lecture 6: Multiplication, Interpolation, and the Chinese Remainder.
Chapter 4 With Question/Answer Animations 1. Chapter Motivation Number theory is the part of mathematics devoted to the study of the integers and their.
Number-Theoretic Algorithms
Introduction to Algorithms: Divide-n-Conquer Algorithms
Divide-and-Conquer 6/30/2018 9:16 AM
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
Number Theory (Chapter 7)
Module #17: Recurrence Relations
Modular Arithmetic and Change of Base
Divide-and-Conquer 7 2  9 4   2   4   7
CSE 373 Data Structures and Algorithms
Module #17: Recurrence Relations
Lecture 28 CSE 331 Nov 7, 2016.
Introduction to Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Section 10.3 Modular Arithmetic
Bellwork 1) Multiply. 3) Find the determinant. 2) Multiply.
Lecture 30 CSE 331 Nov 12, 2012.
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Merge sort and quick sort Binary search
Section 9.3 Modular Arithmetic.
Presentation transcript:

Arithmetic

I. Fast Multiplication and the Master Theorem on Divide and Conquer

How fast can we multiply? Adding two n-bit numbers takes O(n) operations How many operations to multiply two n-bit numbers? Or two n-decimal-digit numbers Difference is a factor of log210 ≈ 3.32 but the individual operations are harder

Grade School Algorithm is Θ(n2) But answer is only O(n) bits: Can we do better?

A Divide and Conquer Algorithm Suppose n is even, n = 2m To compute a∙b Write a = a1∙2m + a0, b = b1∙2m + b0, where a1, a0, b1, b0 are m-bit numbers (numbers < 2m) – the first and last m bits of a and b a∙b = a1b1∙22m + (a1b0+a0b1)∙2m + a0b0 = a1b1∙(22m+2m) + (a1-a0)(b0-b1)∙2m + a0b0∙(2m+1) Only 3 m-bit multiplications!!!

How Fast? T(1)=1 T(n) = 3T(n/2) + cn But how to solve this?

Master Theorem on D+C recurrences T(n) = aT(n/b) + cne Let L = logba Recurrence has the solution: T(n) = Θ(ne) if e > L T(n) = Θ(ne log n) if e = L T(n) = Θ(nL) if e < L Binary search: a=1, b=2, e=0, L=0 [Case 2] Merge sort: a=2, b=2, e=1, L=1 [Case 2] Ordinary mult: a=4, b=2, e=1, L=2 [Case 3] Fast mult: a=3, b=2, e=1, L=lg 3 so Θ(n1.58…) [Case 3]

II: Fast Exponentiation Compute 313: 313 = 3∙3∙3∙3∙3∙3∙3∙3∙3∙3∙3∙3∙3 (12 multiplications, or Θ(exponent)) 313 = 36∙36∙3 (2 multiplications) 36 = 33∙33 (1 multiplication) 33 can be computed with 2 multiplications So 2+1+2 = 5 multiplications in all!

Fast Exponentiation compute ab using registers X,Y,Z,R X:= a; Y:= 1; Z:= b; REPEAT: if Z=0, then return Y R:= remdr(Z,2); Z:= quotnt(Z,2) if R=1,then Y:= X⋅Y X:= X2

Powers by Repeated Squaring Problem: compute ab Method 1: multiply a by itself n-1 times Requires n-1 multiplications Method 2: use successive squaring How many times can you divide n by 2 before it is reduced to 1? Repeated squaring requires between log2n and 2∙log2n multiplications Huge savings! n = 1000 => at most 20 multiplications! (since log21000 < 10) February 28, 2007 Harvard Bits

III. Modular arithmetic 1 2 3 4 5 6 7 6 + 5 = 3 (mod 8) February 28, 2007

Math Quiz 2 x 6 = mod 11 2 x 6 x 5 23 mod 7 2300 1 5 1 1 = (23)100 = 1100 = 1 February 28, 2007

(mod p) notation Think of the (mod p) at the end of the line as referring to everything in the equation (23)100 = 1100 = 1 (mod 7) means “(23)100 , 1100 , and 1 are all equivalent if you divide by 7 and keep just the remainder” Often written a ≡ b (mod p) February 28, 2007 Harvard Bits

Fast Modular Exponentiation Problem: Given q and p and n, find y < p such that qn = y (mod p) Method 1: multiply q by itself n-1 times Requires n-1 multiplications Method 2: use successive squaring Requires about log2n multiplications Same idea works for multiplication modulo p Example: If n is a 500-digit number, we can compute qn (mod p) in about 1700 (= lg 10500) steps. February 28, 2007 Harvard Bits

FINIS