MA/CSSE 473 Day 05. Factors and Primes Recursive division algorithm

Similar documents
Algorithms (II) Yu Yu. Shanghai Jiaotong University

CIS 6930/4930 Computer and Network Security. Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

O Notation (Big Oh) We want to give an upper bound on the amount of time it takes to solve a problem.

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Submit Growable Array exercise Answer Q1-3 from today's in-class quiz.

CPSC 467: Cryptography and Computer Security

8 Primes and Modular Arithmetic

CPSC 467b: Cryptography and Computer Security

SEVENTH EDITION and EXPANDED SEVENTH EDITION

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

CS483 Design and Analysis of Algorithms

1 Maintaining a Dictionary

Module 1: Analyzing the Efficiency of Algorithms

Clock Arithmetic. 1. If it is 9 o clock and you get out of school in 4 hours, when do you get out of school?

An analogy from Calculus: limits

CSCI Honor seminar in algorithms Homework 2 Solution

A field F is a set of numbers that includes the two numbers 0 and 1 and satisfies the properties:

Module 1: Analyzing the Efficiency of Algorithms

Answer the following questions: Q1: ( 15 points) : A) Choose the correct answer of the following questions: نموذج اإلجابة

Chapter 4 Finite Fields

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

22. The Quadratic Sieve and Elliptic Curves. 22.a The Quadratic Sieve

CSE 421 Algorithms: Divide and Conquer

Continuing discussion of CRC s, especially looking at two-bit errors

SECTION 9.2: ARITHMETIC SEQUENCES and PARTIAL SUMS

Lecture 2. Fundamentals of the Analysis of Algorithm Efficiency

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

Mathematical Foundations of Cryptography

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

Grade 11/12 Math Circles Rational Points on an Elliptic Curves Dr. Carmen Bruni November 11, Lest We Forget

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

Number Theory. Zachary Friggstad. Programming Club Meeting

Analysis of Algorithms

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

cse 311: foundations of computing Fall 2015 Lecture 11: Modular arithmetic and applications

Data Structures and Algorithms

Lecture 8: Number theory

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations

[Part 2] Asymmetric-Key Encipherment. Chapter 9. Mathematics of Cryptography. Objectives. Contents. Objectives

Lecture 7: More Arithmetic and Fun With Primes

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture Notes. Advanced Discrete Structures COT S

Solving Recurrences. 1. Express the running time (or use of some other resource) as a recurrence.

CS1800 Discrete Structures Fall 2016 Profs. Gold & Schnyder April 25, CS1800 Discrete Structures Final

CS1800: Mathematical Induction. Professor Kevin Gold

Quiz 1 Solutions. Problem 2. Asymptotics & Recurrences [20 points] (3 parts)

Cpt S 223. School of EECS, WSU

Solving Recurrences. Lecture 23 CS2110 Fall 2011

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6

Outline. Some Review: Divisors. Common Divisors. Primes and Factors. b divides a (or b is a divisor of a) if a = mb for some m

Outline. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

Primes and Factorization

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

Number Theory. Modular Arithmetic

Why do we need math in a data structures course?

Chapter 5. Number Theory. 5.1 Base b representations

Induction and Recursion

Analysis of Algorithms

Design and Analysis of Algorithms

CSC 474 Network Security. Outline. GCD and Euclid s Algorithm. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

Disproof MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Disproof Fall / 16

CS Data Structures and Algorithm Analysis

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Outline. Number Theory and Modular Arithmetic. p-1. Definition: Modular equivalence a b [mod n] (a mod n) = (b mod n) n (a-b)

Speedy Maths. David McQuillan

Basic elements of number theory

Basic elements of number theory

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

Algorithms CMSC Homework set #1 due January 14, 2015

Mathematical Background. Unsigned binary numbers. Powers of 2. Logs and exponents. Mathematical Background. Today, we will review:

Math 31 Lesson Plan. Day 5: Intro to Groups. Elizabeth Gillaspy. September 28, 2011

Topics in Cryptography. Lecture 5: Basic Number Theory

Discrete Mathematics GCD, LCM, RSA Algorithm

Public Key Encryption

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

CS 310 Advanced Data Structures and Algorithms

R ij = 2. Using all of these facts together, you can solve problem number 9.

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Learning Module 1 - Basic Algebra Review (Appendix A)

Algebra. Modular arithmetic can be handled mathematically by introducing a congruence relation on the integers described in the above example.

CSC 474 Information Systems Security

MATH 433 Applied Algebra Lecture 4: Modular arithmetic (continued). Linear congruences.

Math 131 notes. Jason Riedy. 6 October, Linear Diophantine equations : Likely delayed 6

i=1 i B[i] B[i] + A[i, j]; c n for j n downto i + 1 do c n i=1 (n i) C[i] C[i] + A[i, j]; c n

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

CSE 20 DISCRETE MATH. Fall

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

Lecture 8 HASHING!!!!!

Algorithm Design and Analysis

Induction and recursion. Chapter 5

Cpt S 223. School of EECS, WSU

Transcription:

MA/CSSE 473 Day 05 actors and Primes Recursive division algorithm

MA/CSSE 473 Day 05 HW 2 due tonight, 3 is due Monday Student Questions Asymptotic Analysis example: summation Review topics I don t plan to cover in class Continue Algorithm Overview/Review Integer Primality Testing and actoring Modular Arithmetic intro Euclid s Algorithm

Asymptotic Analysis Example ind a simple big Theta expression (as a function of n) for the following sum when 0 < c < 1 when c = 1 when c > 1 f(n) = 1 + c + c 2 + c 3 + + c n

Quick look at review topics in textbook REVIEW THREAD

Textbook Topics I Won't Cover in Class Chapter 1 topics that I will not discuss in detail unless you have questions. They should be review or some of them, there will be review problems in the homework Sieve of Eratosthenes (all primes less than n) Algorithm Specification, Design, Proof, Coding Problem types : sorting, searching, string processing, graph problems, combinatorial problems, geometric problems, numerical problems Data Structures: ArrayLists, LinkedLists, trees, search trees, sets, dictionaries,

Textbook Topics I Won't Cover* Chapter 2 Empirical analysis of algorithms should be review I believe that we have covered everything else in the chapter except amortized algorithms and recurrence relations We will discuss amortized algorithms Recurrence relations are covered in CSSE 230 and MA 375. We'll review particular types as we encounter them. *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 3 Review Bubble sort, selection sort, and their analysis Sequential search and simple string matching *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 4 Review Mergesort, quicksort, and their analysis Binary search Binary Tree Traversal Orders (pre, post, in, level) *Unless you ask me to

Textbook Topics I Won't Cover* Chapter 5 Review Insertion Sort and its analysis Search, insertion, delete in Binary Tree AVL tree insertion and rebalance *Unless you ask me to

Efficient ibonacci Algorithm? Let X be the matrix Then also How many additions and multiplications of numbers are necessary to multiply two 2x2 matrices? If n = 2 k, how many matrix multiplications does it take to compute X n? O(log n), it seems. But there is a catch! 1 1 1 0 1 0 2 1 X 1 0 1 1 0 2 2 1 3 2, X and X X n n n

g Hidden because not ready for prime Refine T(n) calculations, time (the time yet. for computing the n th ibonacci number) for each of our three algorithms Recursive (fib1) We originally had T(n) Ѳ((n)) Ѳ(2 0.694n ) We assumed that addition was constant time. Since each addition is Ѳ(n), the whole thing is Ѳ(n (n)) Array (fib2) We originally had T(n) Ѳ(n), because of n additions. Since each addition is Ѳ(n), the whole thing is Ѳ(n 2 ) Matrix multiplication approach (fib3) We saw that Ѳ(log n) 2x2 matrix multiplications give us n. Let M(k) be the time required to multiply two k bit numbers. M(k) Ѳ(k a ) for some a with 1 a 2. It's easy to see that T(n) O(Ml(n) log n) Can we show that T(n) O(M(n))? Do it for a = 2 and a = log 2 (3) If the multiplication of numbers is better than O(n 2 ), so is finding the n th ibonacci number. http://www.rose-hulman.edu/class/csse/csse473/201310/inclasscode/day06_ibanalysis_division_exponentiation/

Integer Division Modular arithmetic Euclid's Algorithm Heading toward Primality Testing ARITHMETIC THREAD

ACTORING and PRIMALITY Two important problems ACTORING: Given a number N, express it as a product of its prime factors PRIMALITY: Given a number N, determine whether it is prime Where we will go with this eventually actoring is hard The best algorithms known so far require time that is exponential in the number of bits of N Primality testing is comparatively easy A strange disparity for these closely related problems Exploited by cryptographic algorithms More on these problems later irst, more math and computational background

Recap: Arithmetic Run times or operations on two k bit numbers: Addition: Ѳ(k) Multiplication: Standard algorithm: Ѳ(k 2 ) "Gauss enhanced": Ѳ(k 1.59 ), but with a lot of overhead. Division (We won't ponder it in detail, but see next slide): Ѳ(k 2 )

Algorithm for Integer Division Let's work through divide(19, 4). Analysis?

Modular arithmetic definitions x modulo N is the remainder when x is divided by N. I.e., If x = qn + r, where 0 r < N (q and r are unique!), then x modulo N is equal to r. x and y are congruent modulo N, which is written as xy(mod N), if and only if N divides (x y). i.e., there is an integer k such that x y = kn. In a context like this, a divides b means "divides with no remainder", i.e. "a is a factor of b." Example: 253 13 (mod 60)

Modular arithmetic properties Substitution rule If x x' (mod N) and y y' (mod N), then x + y x' + y' (mod N), and xy x'y' (mod N) Associativity x + (y + z) (x + y) + z (mod N) Commutativity xy yx (mod N) Distributivity x(y+z) xy +yz (mod N)

Modular Addition and Multiplication To add two integers x and y modulo N (where k = log N (the number of bits in N), begin with regular addition. x and y are in the range, so x + y is in range If the sum is greater than N 1, subtract N. Run time is Ѳ ( ) To multiply x and y modulo N, begin with regular multiplication, which is quadratic in k. The result is in range and has at most bits. Compute the remainder when dividing by N, quadratic time. So entire operation is Ѳ( )

Modular Addition and Multiplication To add two integers x and y modulo N (where k = log N, begin with regular addition. x and y are in the range 0 to N 1, so x + y is in range 0 to 2N 1 If the sum is greater than N 1, subtract N. Run time is Ѳ (k ) To multiply x and y, begin with regular multiplication, which is quadratic in n. The result is in range 0 to (N 1) 2 and has at most 2k bits. Then compute the remainder when dividing by N, quadratic time in k. So entire operation is Ѳ(k 2 )

Modular Exponentiation In some cryptosystems, we need to compute x y modulo N, where all three numbers are several hundred bits long. Can it be done quickly? Can we simply take x y and then figure out the remainder modulo N? Suppose x and y are only 20 bits long. x y is at least (2 19 ) (219 ), which is about 10 million bits long. Imagine how big it will be if y is a 500 bit number! To save space, we could repeatedly multiply by x, taking the remainder modulo N each time. If y is 500 bits, then there would be 2 500 bit multiplications. This algorithm is exponential in the length of y. Ouch!

Modular Exponentiation Algorithm Let k be the maximum number of bits in x, y, or N The algorithm requires at most recursive calls Each call is Ѳ( ) So the overall algorithm is Ѳ( )

Modular Exponentiation Algorithm Let n be the maximum number of bits in x, y, or N The algorithm requires at most k recursive calls Each call is Ѳ(k 2 ) So the overall algorithm is Ѳ(k 3 )