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.

Slides:



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

Recursion Michael Ernst UW CSE 140 To seal: moisten flap, fold over, and seal.
CSE 311 Foundations of Computing I Lecture 13 Number Theory Autumn 2012 CSE
Basic properties of the integers
Recursion Michael Ernst CSE 190p University of Washington To seal: moisten flap, fold over, and seal.
Cryptography and Network Security Chapter 4
Elementary Number Theory and Methods of Proof. Basic Definitions An integer n is an even number if there exists an integer k such that n = 2k. An integer.
3 Gallon Jug5 Gallon Jug Greatest Common Divisor Lecture 8: Sep 30.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
CSE 311 Foundations of Computing I Lecture 12 Primes, GCD, Modular Inverse Spring
CS555Spring 2012/Topic 61 Cryptography CS 555 Topic 6: Number Theory Basics.
Quiz 2 key.
CSCI 1900 Discrete Structures
1 Properties of Integers Objectives At the end of this unit, students should be able to: State the division algorithm Apply the division algorithm Find.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19: Recursion.
COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
CPSC 3730 Cryptography and Network Security
1 Cryptography and Network Security Third Edition by William Stallings Lecture slides by Lawrie Brown Chapter 4 – Finite Fields.
Cryptography and Network Security Introduction to Finite Fields.
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.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
Chapter 4 – Finite Fields
Data Security and Encryption (CSE348) 1. Lecture # 12 2.
MA/CSSE 473 Day 19 Exam Prep. MA/CSSE 473 Day 19 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
Information Security Lab. Dept. of Computer Engineering 87/121 PART I Symmetric Ciphers CHAPTER 4 Finite Fields 4.1 Groups, Rings, and Fields 4.2 Modular.
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.
Modular (Remainder) Arithmetic n = qk + r (for some k; r < k) eg 37 = (2)(17) + 3 Divisibility notation: 17 | n mod k = r 37 mod 17 = 3.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
COMPSCI 102 Introduction to Discrete Mathematics.
CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.
4/3/2003CSE More Math CSE Algorithms Euclidean Algorithm Divide and Conquer.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Cryptography and Network Security Chapter 4. Introduction  will now introduce finite fields  of increasing importance in cryptography AES, Elliptic.
CSE 311 Foundations of Computing I Lecture 14 Euclid’s Algorithm Mathematical Induction Autumn 2012 CSE
Application: Algorithms Lecture 20 Section 3.8 Wed, Feb 21, 2007.
AF2. Turn off your phones Primes, gcd, some examples, reading.
Lecture 3.1: Public Key Cryptography I CS 436/636/736 Spring 2015 Nitesh Saxena.
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
AF2. Turn off your phones Primes, gcd, some examples, reading.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Cryptography and Network Security Third Edition by William Stallings Lecture slides by Lawrie Brown.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division Fermat's little theorem intro.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
Recursive Algorithms Section 5.4.
MA/CSSE 473 Day 07 Extended Euclid's Algorithm Modular Division
Lecture 4 The Euclidean Algorithm
MA/CSSE 473 Day 06 Euclid's Algorithm.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 06 Euclid's Algorithm.
Advanced Algorithms Analysis and Design
Numerical Algorithms x x-1 Numerical Algorithms
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Greatest Common Divisor
CSE 311 Foundations of Computing I
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Number Theory (Chapter 7)
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
From the last time: gcd(a, b) can be characterized in two different ways: It is the least positive value of ax + by where x and y range over integers.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Presentation transcript:

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 Euclid's algorithm

REVIEW THREAD Quick look at review topics in textbook

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 –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

ARITHMETIC THREAD Euclid's Algorithm Heading toward Primality Testing

Euclid's Algorithm: the problem One of the oldest known algorithms (about 2500 years old) The problem: Find the greatest common divisor (gcd) of two non-negative integers a and b. The approach you learned in elementaryschool: –Completely factor each number –find common factors (with multiplicity) –multiply the common factors together to get the gcd Factoring is hard! Simpler approach is needed Q1

Euclid's Algorithm: the basis Based on the following rule: –If x and y are positive integers with x ≥ y, then gcd(x, y) = gcd(y, x mod y) Proof of Euclid's rule: –It suffices to show the simpler rule gcd(x, y) = gcd(y, x - y) since x mod y can be obtained from x and y by repeated subtraction –Any integer that divides both x and y must also divide x – y, so gcd(x, y) ≤ gcd(y, x – y) –Any integer that divides both y and x - y must also divide x, so gcd(y, x-y) ≤ gcd(y, x) –Putting these together, so gcd(y, x-y) = gcd(y, x)

Euclid's Algorithm: the algorithm Example: euclid(60, 36) Does the algorithm work? How efficient is it? Q2

Euclid's Algorithm: the analysis Lemma: If a ≥ b, then a % b < a/2 Proof –If b ≤ a/2, then a % b < b ≤ a/2 –If b > a/2, then a % b = a – b < a/2 Application –After two recursive calls, both a and b are less than half of what they were, (i.e. reduced by at least 1 bit) –Thus if a and b have n bits, at most 2n recursive calls are needed. –Each recursive call involves a division, Ѳ(n 2 ) –Entire algorithm is Ѳ(n 3 )

gcd and linear combinations Lemma: If d divides both a and b, and d = ax + by for some integers x and y, then d = gcd(a,b) Proof –By the first of the two conditions, d is a common divisor of a and b. It cannot exceed the greatest common divisor, so d ≤ gcd(a, b) –gcd(a, b) is a common divisor of a and b, so it must divide ax + by = d. Thus gcd(a, b) ≤ d –Putting these together, gcd(a, b) = d If we can supply the x and y as in the lemma, we know that d is the gcd. It turns out that a simple modification of Euclid's algorithm will calculate the x and y. Q3

Extended Euclid Algorithm Proof that it works –First, the number d it produces really is the gcd of a and b. We can just ignore the x and y values, and we have the same algorithm as before.

Extended Euclid Algorithm: proof Proof that it works –First, the number d it produces really is gcd (a,b) We can just ignore the x and y values, and we have the same algorithm as before. –We must show that the x and y it returns are such that ax + by =d. –We do that by induction on b. Q4

Proof that ax+by = d (induction on b) Base case: b=0 Then gcd(a,b) = a, and the algorithm produces x = 1, y = 0.  Induction step: b > 0. – It finds gcd(a, b) by calling euclidExtended(b, a%b) –Since a%b is smaller than b, by induction the x' and y' returned by the recursive call are such that gcd(b, a %b) = bx'+ (a%b)y' –We can write a % b as a –  a/b  * b –d = gcd(a, b) = gcd(b, a%b) = bx' + (a%b)y' = bx' +(a –  a/b  * b)y' = ay' +b(x' -  a/b  y') –Thus x = y' and y = x' -  a/b  y' are the numbers that make ax + by = d –This x and y are the numbers returned by the algorithm. Q4

Example: gcd (33, 14) 33 = 2* = 2 * = 1 * = 4 * 1 + 0, so gcd(33, 14) = 1. Now work backwards 1 = Substitute 4 = *5. 1 = 5 – (14 - 2*5) = 3* Substitute 5 = *14 1 = 3(33 - 2*14) -14 = 3 * 33 – 7 * 14 Thus x = 3 and y = -7 Done! Q5-6