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

Slides:



Advertisements
Similar presentations
Cryptography and Network Security
Advertisements

Number Theory and Cryptography
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
Congruence class arithmetic. Definitions: a ≡ b mod m iff a mod m = b mod m. a  [b] iff a ≡ b mod m.
Arithmetic.

MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
CS 312: Algorithm Analysis Lecture #3: Algorithms for Modular Arithmetic, Modular Exponentiation This work is licensed under a Creative Commons Attribution-Share.
MA/CSSE 473 Day 22 Binary Heaps Heapsort Answers to student questions Exam 2 Tuesday, Nov 4 in class.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Chapter 1 Introduction. Goals Why the choice of algorithms is so critical when dealing with large inputs Basic mathematical background Review of Recursion.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
Copyright © Curt Hill Divisibility and Modular Arithmetic A Topic in Number Theory.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Data Security and Encryption (CSE348) 1. Lecture # 12 2.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
MA/CSSE 473 Day 06 Euclid's Algorithm. MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Lecture 3.1: Public Key Cryptography I CS 436/636/736 Spring 2015 Nitesh Saxena.
9.1 Primes and Related Congruence Equations 23 Sep 2013.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Implementation of Public Key Encryption Algorithms
MA/CSSE 473 Day 30 Optimal BSTs. MA/CSSE 473 Day 30 Student Questions Optimal Linked Lists Expected Lookup time in a Binary Tree Optimal Binary Tree (intro)
MA/CSSE 473 Day 07 Euclid's Algorithm. MA/CSSE 473 Day 07 Student Questions Review topics not covered in class Euclid's algorithm (if there is time) extended.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
MA/CSSE 473 Days Optimal linked lists Optimal BSTs.
MA/CSSE 473 Day 04 Multiplication runtime Multiplication based on Gauss formula Mathematical induction review.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
MA/CSSE 473 Day 06 Mathematical Induction Modular Arithmetic Do question 1 on today's quiz (work with another person)
MA/CSSE 473 Day 06 DivisionPrimes Modular Arithmetic.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
CSE 311 Foundations of Computing I Lecture 11 Modular Exponentiation and Primes Autumn 2011 CSE 3111.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division Fermat's little theorem intro.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division
MA/CSSE 473 Day 06 Euclid's Algorithm.
MA/CSSE 473 Day 06 Euclid's Algorithm.
Congruence class arithmetic
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers
Lecture No.43 Data Structures Dr. Sohail Aslam.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Randomized Algorithms
Lecture 22 Binary Search Trees Chapter 10 of textbook
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees
Hashing Exercises.
Number Theory (Chapter 7)
Teach A level Computing: Algorithms and Data Structures
CSE 326: Data Structures: Midterm Review
Building Java Programs
Lecture 20 Guest lecturer: Neal Gupta
Randomized Algorithms
Data Structures Review Session
CSE 311 Foundations of Computing I
Binary Trees (and Big “O” notation)
Lecture 3.1: Public Key Cryptography I
Data Structures and Algorithm Analysis Priority Queues (Heaps)
Cryptography Lecture 20.
Cryptography Lecture 16.
Presentation transcript:

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

MA/CSSE 473 Day 05 Student Questions One more proof by strong induction List of review topics I don’t plan to cover in class Continue Arithmetic Algorithms Toward Integer Primality Testing and Factoring Efficient Integer Division Algorithm Modular Arithmetic intro Pass around attendance sheet.

Quick look at review topics in textbook Review Thread

Another Induction Example Extended Binary Tree (EBT) An Extended Binary tree is either an external node, or an (internal) root node and two EBTs TL and TR. We draw internal nodes as circles and external nodes as squares. Generic picture and detailed picture. This is simply an alternative way of viewing binary trees, in which we view the null pointers as “places” where a search can end or an element can be inserted.

A property of EBTs What is the crux of any induction proof? Property P(N): For any N>=0, any EBT with N internal nodes has _______ external nodes. Proof by strong induction, based on the recursive definition. A notation for this problem: IN(T), EN(T) Note that, like some other simple examples, this one can also be done without induction. But the purpose of this exercise is practice with strong induction, especially on binary trees. What is the crux of any induction proof? Finding a way to relate the properties for larger values (in this case larger trees) to the property for smaller values (smaller trees). Do the proof now. If time, ask students how we can do this without induction: N nodes contain 2N pointers. N-1 of them point to other nodes, so N+1 must point to nothing.

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 For 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 later. 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, insert, delete in Binary Search treeTree AVL tree insertion and rebalance We will review the analysis of AVL trees. *Unless you ask me to

Interlude

Arithmetic thread Heading toward Primality Testing Integer Division Modular arithmetic Euclid's Algorithm Arithmetic thread

FACTORING and PRIMALITY Two important problems FACTORING: 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 Factoring 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 systems More on these problems later First, some more math and computational background…

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

Algorithm for Integer Division divide(19, 4): q, r = divide(9, 4) q, r = divide (4, 4) q, r = divide(2, 4) q, r = divide(1, 4) q, r = divide(0, 4) = 0, 0 x is odd, so r = 1 return 0, 1 q, r, = 0, 2 return 0, 2 q, r = 0, 4 q, r = 1, 0 return 1, 0 q, r, = 2, 0 q, r = 2, 1 return 2, 1 q, r = 4, 2 q, r, = 4, 3 return 4, 3 Analysis: If k is max number of bits in x, y, each recursive call is O(k), and at most k calls, so altogether O( k^2). Let's work through divide(19, 4). Analysis?

Modular arithmetic This idea has many uses In this course we will use it for encryption and for primality testing Modular arithmetic

Modular arithmetic definitions x modulo N (written as x % N in many programming languages) 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 xy (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), 253  373 (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. Assume that x and y are in the range_____, so x + y is in range _______ If the sum is greater than N-1, subtract N. Running 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 Ѳ( ) 0 to N – 1, 0 to 2(N-1), Theta(k). 0 to (N-1)2 , 2k Theta(k2) More details on next slide

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

Modular Exponentiation In some cryptosystems, we need to compute xy modulo N, where all three numbers are several hundred bits long. Can it be done quickly? Can we simply take xy and then figure out the remainder modulo N? Suppose x and y are only 20 bits long. xy is at least (219)(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 2500 bit multiplications. This algorithm is exponential in the length of y. Ouch! To do better, we can use an algorithm like our previous recursive exponentiation algorithm

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 Ѳ( ) Answers: k, k2, k3

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 Ѳ(k2) So the overall algorithm is Ѳ(k3)